Hi,
I am currently working on a big PowerShell GUI application which combines a bunch of functions.
As these functions connect to remote machines I need to think about authentication. So I added a button which calls Get-Credential and saves this to a variable (let’s say $savedcred). But I also want to leave the possibility that the functions can be launched without having to explicitly enter credentials (so just using the credentials of the currently logged on user from where the application is launched).
So an example of a function would be:
if ($savedcred) { Enter-PSSession -ComputerName computer1 -Credentials $savedcred } else { Enter-PSSession -ComputerName computer1 }
But as you notice, this will render me with a lot of repetitive code. I have been trying to find a way to get the credentials of the currently loggedon user in and put it in a PSCredential type object, so that I declare the $savecred at the start of my application and if necessary, it can get overwritten with a new user in case the Credential button is used.
I have been looking for instance into [System.Security.Principal.WindowsIdentity] but there seems no way to inject this into the PSCredential object.
Anyone already did something like this? Is it possible at all?