Bonjour,
J'utiliserai bien un script powershell pour mapper mes lecteurs. Je lance depuis windows10home FR (jai test de lancer le script en admin, désactivation UAC), mais j'ai un message/problème :
Set-Content : L'accès au chemin d'accès 'C:\Users\nom_user\password' est refusé.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #Requires -Version 5.1.19041.1
$credentialFile = "C:\Users\nom_user\password"
$smbPath = @{
"X:" = "\\ip_srv\dossier01";
"Y:" = "\\ip_srv\dossier02";
}
function getCredentials {
Write-Host "Get credentials for $remotePath"
$credential = Get-Credential
"$($credential.UserName):$($credential.Password | ConvertFrom-SecureString)" | Set-Content -Force -NoNewline $credentialFile
}
if (-not $(Test-Path $credentialFile -PathType leaf)) {
getCredentials
} else {
$credentialFileContent = $(Get-Content -Path $credentialFile).Split(":")
if ($credentialFileContent.Length -eq 0) {
getCredentials
}
}
$username = $credentialFileContent[0]
$password = $credentialFileContent[1]
$encrypted = $password | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PsCredential($username, $encrypted)
$smbPath.GetEnumerator()|ForEach-Object {
$smbMapping = Get-SmbMapping
if (-not ($smbMapping.LocalPath -eq $_.Name)) {
Write-Host "Mounting $_.Name from $_.Value"
New-SmbMapping -LocalPath $_.Name -RemotePath $_.Value -Persistent $true -UserName $credential.UserName -Password $Credential.GetNetworkCredential().Password
}
} |
Ça a pour but de demander ID+password et de stocker les infos cryptés dans le dossier "C:\Users\nom_user\password"
Est-ce que vous pouvez m'aider
Partager