I am trying change virtual memory path (pagefile.sys) for temporary storage drive in windows machine , then machine needs to restart post changing “pagefile.sys”.
After the change of this, also i m changing drive letter to next alphabet letter.
In powershell resource block i have added “not_if” condition to check the value as true/false. But still its getting executed twice in chef run.
Please find below code snippet and help me on this.
powershell 'change the virtual memory path' do
code <<-EOH
$d_drive_pagefile_settings = Get-WmiObject Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ D:'"
if (-not ([string]::IsNullOrEmpty($d_drive_pagefile_settings)))
{
Import-Module ("#{Chef::Config[:file_cache_path]}/#{manage_virtualmemory_source_script}")
Set-OSCVirtualMemory -SystemManagedSize C:
Set-OSCVirtualMemory -None -DriveLetter D:
Write-Host "d drive has page file settings"
}
EOH
not_if <<-EOH
([string]::IsNullOrEmpty((Get-WmiObject Win32_PageFileSetting -Filter "SettingID='pagefile.sys @ D:'")))
EOH
notifies :request, 'windows_reboot[restart_post_virtual_mem_update]', :immediately
end
windows_reboot 'restart_post_virtual_mem_update' do
timeout 1
reason 'Restarting the machine for changing virtual memory path'
action :nothing
end
powershell 'change the drive letter' do
code <<-EOH
$drive = Get-WmiObject -Class win32_volume -Filter "DriveLetter = 'D:'"
Set-WmiInstance -input $drive -Arguments @{DriveLetter="F:";}
EOH
not_if {reboot_pending?}
end