How to query Windows Server Hibernate status ? (through existing hiberfil.sys file testing)
hello all,
i'd know if can modify script can query multiple servers hibernate files ?
i've come accros url (http://powershell.com/cs/media/p/3849.aspx) somehow failed when supplied array script:
$onlineservers = @() get-qadcomputer -searchroot 'domain.com/domain servers/windows 2008 servers/dmz prod' -osname "windows*server*" | %{$pingresult = get-wmiobject -query "select * win32_pingstatus address='$($_.name)'" if ($pingresult.statuscode -eq 0) { $onlineservers += "$($_.name)" } } function check-fileexists ([string]$path, [switch]$output) { begin { # display content, if -? specified @ command line if ($args -contains '-?') { write-host -foregroundcolor yellow "`npurpose:`npipeline function! accepts computer names pipeline & checks see whether provided path exists on machine. if output switch provided outputs computers file exists on pipeline." write-host -foregroundcolor green "`nsyntax:`n`$computername_array | check-fileexists [[-path] <string>] [-output]`n" break } $computers_fileexists = @() } process { test-pipeline $computer = $_ write-host "checking $computer for: $path" if (!($path -like "hk*")) { # test file/folder/registry key exists @ specified path/location if (test-path -path $path) { write-host -foregroundcolor green "file/folder exists on $computer!`n" $computers_fileexists += $computer } else { write-warning "file/folder not exist on $computer!!`n" } } else { [string]$registrybasekey = $path.split(':')[0] [string]$subkey = $path.split(':')[1].substring(1) switch ($registrybasekey) { "hklm" { $hkey = 'localmachine' } "hkcu" { $hkey = 'currentuser' } default { write-warning "registry path must start 'hklm:\' or 'hkcu:\'" } } # test see if supplied registry key exist on current machine $registrypath = [microsoft.win32.registrykey]::openremotebasekey($hkey,$computer).opensubkey($subkey) if ($registrypath -ne $null) { write-host -foregroundcolor green "registry key exists on $computer!`n" $computers_fileexists += $computer } else { write-warning "registry key not exist on $computer!!`n" } } } end { if ($output.ispresent) { write-output $computers_fileexists } } } foreach($server in $onlineservers) { check-fileexists ("c:\hiberfil.sys", "$server") }
the problem above scipt that: eventhough file c:\hiberfil.sys exist on server says doesn't exist. when remove server / computername parameter works local laptop got file?
wrong result always:
checking for: c:\hiberfil.sys server01-vm warning: file/folder not exist on !!
i tried change hidden file settings still same result on both server 2008 , 2003
any appreciated.
/* server support specialist */
gwmi cim_datafile -filter "path='\\'" | ? {$_.name -match 'hiberfil.sys'} or
gwmi -query "associators of {win32_directory.name='c:\'} resultclass=cim_datafile" | ? {$_.name -match 'hiberfil.sys'}
Windows Server > Windows PowerShell
Comments
Post a Comment