Powershell to query current hibernate status of all Windows Server in the domain ?

Hi All,

How can I view the current power scheme like the following command does:

C:\>powercfg -l

Existing Power Schemes (* Active)
———————————–
Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *
Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)
Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)

Open in new window


I tried using the modified script:

invoke-wmimethod -cred $cred -path win32_process -name create -argumentlist “powercfg.exe -l” -ComputerName $name

Open in new window

but it doesn’t show up anything useful ?

__GENUS : 2
__CLASS : __PARAMETERS
__SUPERCLASS :
__DYNASTY : __PARAMETERS
__RELPATH :
__PROPERTY_COUNT : 2
__DERIVATION : {}
__SERVER :
__NAMESPACE :
__PATH :
ProcessId : 6128
ReturnValue : 0

Open in new window

# Source: http://www.maartendamen.com/2011/02/disable-hibernation-on-multiple-windows-2008-servers-using-windows-powershell/

# Ask for credentials used to do remote WMI.
$cred    	= Get-Credential DOMAIN\account

# Filter used for active directory query. Only 2008 server machines.
$strFilter 	= "(&(objectClass=computer)(operatingSystem=Windows *2008*))"

$objDomain 	= New-Object System.DirectoryServices.DirectoryEntry
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

$colResults = $objSearcher.FindAll()

# Loop through list of servers.
foreach ($objResult in $colresults)
{
	$objItem = $objResult.Properties
	$name = $objItem.name[0]

	Write-Host "Disabling hibernation on: $name"

	try {
		invoke-wmimethod -cred $cred -path win32_process -name create -argumentlist "powercfg.exe /h off" -ComputerName $name
	}
	catch {
		Write-Host "Failed to disable hibernation on: $name, no permission or server down?"
		break
	}
	finally {
		Write-Host "Hibernation disabled on: $name"
	}
}

Open in new window

LVL 1
jjozAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jjozAuthor Commented:
Here's what happened after changing the script line into:
Invoke-Command -cred DOMAIN\Administrator -ScriptBlock {"powercfg.exe -l"} -ComputerName "SIBOT02-vm" 

Open in new window


and here's what I got:

Invoke-Command : A parameter cannot be found that matches parameter name 'path'.
At C:\Temp\b2b1eb72-bc03-40b5-8298-867213b8a11d.ps1:1 char:43
+ Invoke-Command -cred DOMAIN\Administrator -path <<<<  win32_process -name create -argumentlist "powercfg.exe -l" -ComputerName "SIBOT02-vm"
    + CategoryInfo          : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeCommandCommand 

Open in new window


while this is the result after I execute the command "winrm quickconfig":

[sibot02-vm] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the servic
e on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or Win
RM. If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information,
 see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionStateBroken

Open in new window


it is still failed anyway ?
0
eli_cookCommented:
Have you configured all of your servers to allow power shell remote management connections? It appears that the error you are receiving in your second post is due to the connection being refused.

If you can apply a group policy to all of your Windows 2008 Servers you can use the following guide to enable power shell remote management via GPO.

http://mctexpert.blogspot.com/2011/03/enable-powershell-v2-remote-management.html

After power shell has been configured to allow remote connections retry your scripts.
0
jjozAuthor Commented:
Ah ok, my environment is mixed 2003 and 2008 servers no 2008R2 yet, so I there anything that I should push install from the wsus to enable PS 2.0 ?
0
eli_cookCommented:
Here is the Microsoft reference for Windows Management Framework Core Package (PowerShell 2.0 and WinRM 2.0)
http://support.microsoft.com/kb/968930
It looks like the Microsoft KB article # is 968930 - I think you can identify the update in WSUS with the KB article #.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jjozAuthor Commented:
thanks !
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.