Requesting a password.
1 2 | $Credentials = Get-Credential -Credential "domaine\dwuibail_adm" $ldWS = New-WebServiceProxy -uri http://serverlandesk.leblogosd.lan/MBSDKService/MsgSDK.asmx ? WSDL -Credential $Credentials |
Passwords in plain text.
1 2 3 4 | $username = “domaine\dwuibail_adm” $password = “Motdepasse” $Credentials = New-Object System.Management.Automation.PSCredential $Username , $Password $ldWS = New-WebServiceProxy -uri http://serverlandesk.leblogosd.lan/MBSDKService/MsgSDK.asmx ? WSDL -Credential $Credentials |
Encrypting passwords
The encryption and decryption can only be done on the same machine and by the same account
- Get the encrypted key
1 | "MyPassword" | Convertto-SecureString -AsPlainText -Force | ConvertFrom-SecureString | Out-file C:\temp\PassKey.txt |
- Using the encrypted key
1 2 3 4 5 6 7 8 9 | $user = "moncompte" $password = ConvertTo-SecureString -String "01000000d08c9ddf01151111111111111111111111111 ..... 111111111111111" $creds = New-Object -TypeName System.Management.Automation.PsCredential -ArgumentList ($user, $password) #Exemple 1 New-PSDrive -Name "P" -Root "\\nas\dml" -PSProvider "FileSystem" -Credential $creds #Exemple 2 $Pass = $creds.getnetworkcredential().Password |
0 Comments