dbatools icon indicating copy to clipboard operation
dbatools copied to clipboard

Get-DBAPowerPlan fails if PowerShell is not running as Admin

Open sql-williamd opened this issue 8 years ago • 5 comments

Before submitting a bug report:

  • [x] Ensure you are able to reproduce it on the latest released version (we release often)
  • [ ] Verified this bug is not already reported in an issue
  • [ ] Verified errors are not related to permissions
  • [x] Can reproduce in a clean PowerShell session (clean = powershell -NoProfile)

Steps to Reproduce

Open PowerShell console in non-Admin mode and run the command

  Get-DBAPowerPlan -ComputerName $MyMachine 

Expected Behavior

Give me a warning that elevated permissions are needed

Actual Behavior

A "timeout" occurs when different protocols are attempted, then it fails with the following message

WARNING: [00:21:47][Get-DbaPowerPlan] Can't get Power Plan Info for $MyMachine. Check logs for more details. | Multiple 
protocol connections were attempted, but no successful connections could be established with the specified computer.

Environmental data

  • PowerShell:
Name                           Value                                                                                      
----                           -----                                                                                      
PSVersion                      5.1.17763.134                                                                              
PSEdition                      Desktop                                                                                    
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                    
BuildVersion                   10.0.17763.134                                                                             
CLRVersion                     4.0.30319.42000                                                                            
WSManStackVersion              3.0                                                                                        
PSRemotingProtocolVersion      2.3                                                                                        
SerializationVersion           1.1.0.1

sql-williamd avatar Dec 05 '18 23:12 sql-williamd

I am unable to reproduce this, I tested with both admin, and regular PowerShell. I was able to get the plan information in both cases.

Were you able to test in admin mode and received the power plan information, just not without elevation? Do you have permissions to the machine you tried to test?

Adam-Wenger avatar Dec 06 '18 00:12 Adam-Wenger

I can get it to run on my machine when running PowerShell as administrator, non-elevated sessions fail.

This is on my laptop, I have full permissions locally

sql-williamd avatar Dec 06 '18 00:12 sql-williamd

I was able to reproduce this by running Get-DbaPowerPlan on a local non-admin powershell session, targetting my local computer. I'll test it against remote computers later today.

joeywas avatar Dec 06 '18 08:12 joeywas

Running Get-DbaPowerPlan on a local non-admin PowerShell session against a remote computer works without any issues.

Running against localhost:

PS C:\windows\system32> Get-DbaPowerPlan localhost WARNING: [12:09:14][Get-DbaPowerPlan] Can't get Power Plan Info for localhost. Check logs for more details. | Multiple protocol connections were attempted, but no successful connections could be established with the specified computer. PS C:\windows\system32>

DbaTools version 0.9.710

joeywas avatar Dec 06 '18 20:12 joeywas

Something about permissions should probably be added to Get-DbaCmObject, which is called from Get-DbaPowerPlan. I started looking at it, but it's a bit over my head. The Get-DbaCmObject author @FriedrichWeinmann may have a suggestion on how to add permissions check that returns appropriate message.

joeywas avatar Dec 07 '18 22:12 joeywas