There are multiple ways to achieve it. I will suggest using a Get-Credential cmdlet to get the credential and use start-process to run the script or program of your choice. You can also use invoke-command for this purpose to run commands on remote machines of you network, but the approach is not advisable when WinRM is not enabled and I don't want to make it complicated.
So, let's take a look on the script and then we will see how it runs :
$c=Get-Credential
Start-Process c:\windows\notepad.exe -Credential $c
When you run the two lines above, you see a popup which asks your credentials :
Enter credential and then you will see the notepad.exe running with that credential.
This may help you if you are making a program which requires special credentials at some point and user can enter the login and password. Good for any interactive script only. We can also save the credentials and use that. We will see that in next article, till then enjoy!
So, let's take a look on the script and then we will see how it runs :
$c=Get-Credential
Start-Process c:\windows\notepad.exe -Credential $c
When you run the two lines above, you see a popup which asks your credentials :
Enter credential and then you will see the notepad.exe running with that credential.
This may help you if you are making a program which requires special credentials at some point and user can enter the login and password. Good for any interactive script only. We can also save the credentials and use that. We will see that in next article, till then enjoy!
No comments:
Post a Comment