I need to be able to map a couple of drives via a Powershell script during computer logon. The script I have so far (thanks to help on this forum) is below
while ($true)
{
try
{
$Credential = $host.ui.PromptForCredential("Need credentials", "Please enter your user name and password.", "", "NetBiosUserName")
# Prevent cancel that maps PSDrive anyway
if ($Credential)
{
New-PSDrive -Name "T" -PSProvider FileSystem -Root \servernameshare -Persist -Credential $Credential -ErrorAction Stop
}
else
{
throw [System.ComponentModel.Win32Exception]::new(0x80004005) # Invalid login and/or password
}
"OK"
# PSSDrive created, exiting the infinite loop
break
}
catch
{
Write-Warning "Wrong Username and/or password, please retry..."
}
}
"Continue"
The problem is, when I add another drive to be mapped under the one above, like this
New-PSDrive -Name "P" -PSProvider FileSystem -Root \servernameshare -Persist -Credential $Credential -ErrorAction Stop
New-PSDrive -Name "T" -PSProvider FileSystem -Root \servernameshare -Persist -Credential $Credential -ErrorAction Stop
the script just loops with "wrong username/password....." message
If I comment out either drive mapping line it works fine
any help would be appreciated
Thanks
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…