Pour encrypter un mot de passe afin de l’utiliser par la suite avec l’option
Voici le script :
# Path to the script to be created:
$path = ‘c:scriptstempMyIdentity.ps1’
# Create empty template script:
New-Item -ItemType File $path -Force -ErrorAction SilentlyContinue | Out-Null
$pwd = Read-Host ‘Enter Password’ -AsSecureString
$user = Read-Host ‘Enter Username’
$pwdencrypted = $pwd | ConvertFrom-SecureString
$private:ofs = ‘ ‘
(‘$password = « {0}"’ -f $pwdencrypted) | Out-File $path</p> <p>’$passwordSecure = ConvertTo-SecureString -String $password’ |Out-File $path -Append</p> <p>(‘$cred = New-Object system.Management.Automation.PSCredential("{0}", $passwordSecure)’ -f $user) | Out-File $path -Append</p> <p>’$cred’ | Out-File $path -Append</p> <p>ise $path</p>"</p> »
loumanou
27 mars 2017 at 16h24
Bonjour,
*Serait-il possible d’avoir une version corrigée et commentée de script svp ? le dernier paragraphe semble incorrecte …( ’ ???)
D’avance merci.
Thomas Delahaye
29 mars 2017 at 21h04
Bonsoir,
En fait le script dans la page contient des morceaux de code HTML …
Je vous conseil d’utiliser ce bout de code très simple qui fait son office :
[powershell]
#CREATE THE FILE
Read-host -assecurestring | convertfrom-securestring | out-file C:\temp\creds.txt
#USE IT
$creadsPwd = get-content C:\temp\creds.txt | convertto-securestring
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist "myusername",$creadsPwd
[/powershell]
Bon scripting
Thomas