ERROR: New-PSDrive : Multiple connections to a server or shared resource by the same user
Posted: Fri Mar 08, 2019 6:47 am
I am copying one file from about 10 different servers with the below foreach code. I receive this error at some point during the copies, but I can't figure out why I'm getting it. I have googled and found this to be issues for others, but could not find any solution that would help. Any help would be greatly appreciated.
ERROR: New-PSDrive : Multiple connections to a server or shared resource by the same user
foreach ($Server in $Servers)
{
$pass = "PA$$W0RD" | ConvertTo-SecureString -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential("us\account", $pass)
New-PSDrive -name Z -Root \\$Server\c$ -Credential $cred -PSProvider filesystem
$progressbaroverlay1.step + 10
foreach ($Brand in $Brands)
{
[System.Windows.Forms.Application]::DoEvents()
$sourceFile = "Z:\programdata\$Brand setup\server configuration.xml"
$destFile = "$Server-$Brand.xml"
if (!(Test-Path "Z:\programdata\$Brand setup"))
{
Break
}
Copy-Item $sourceFile -Destination $destFile
}
[System.Windows.Forms.Application]::DoEvents()
Remove-PSDrive Z
}
ERROR: New-PSDrive : Multiple connections to a server or shared resource by the same user
foreach ($Server in $Servers)
{
$pass = "PA$$W0RD" | ConvertTo-SecureString -AsPlainText -Force
$Cred = New-Object System.Management.Automation.PsCredential("us\account", $pass)
New-PSDrive -name Z -Root \\$Server\c$ -Credential $cred -PSProvider filesystem
$progressbaroverlay1.step + 10
foreach ($Brand in $Brands)
{
[System.Windows.Forms.Application]::DoEvents()
$sourceFile = "Z:\programdata\$Brand setup\server configuration.xml"
$destFile = "$Server-$Brand.xml"
if (!(Test-Path "Z:\programdata\$Brand setup"))
{
Break
}
Copy-Item $sourceFile -Destination $destFile
}
[System.Windows.Forms.Application]::DoEvents()
Remove-PSDrive Z
}