Get-Credential

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Get-Credential

Post by MarvelManiac »

Hello,
Creating a gui to change power plans. This is done. But I noticed we use on one PC that we log in as a normal user because multiple techs use it

ISE works just fine but when I attempt this in gui form, it does not retrieve the current power plan
  1. $sb = { (powercfg /l | ? { $_.Contains('*') -and $_.Contains('GUID') }).Split()[3] }
  2. if($env:computername -eq 'PCEVERYONEUSES')
  3. {
  4. $power = Invoke-Command -RunAsAdministrator -ScriptBlock $sb -ComputerName $computer -Credential (Get-Credential)
  5. }
If I run the application as admin first it works...
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Get-Credential

Post by jvierra »

Works fine for me. Don't use "RunAsAdministrator"
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Get-Credential

Post by MarvelManiac »

Hmm, even with not using -RunAsAdministrator its failing :(
It's okay... Thank you so much for your time!
This topic is 5 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked