Hello Powershell community.
I’m having an issue with a script.
I’m using it to send a file to a list of computers. everything works fine at the beggining but after a while i get this error :
New-PSDrive : The local device name has a remembered connection to another network resource
Here is my script
[pre]
Remove-PSDrive -Name k -ErrorAction silentlyContinue #in case there already is a K: $liste = get-content "\\*****\3-Clients\3-Run\Manpower\scripts\listepchd.txt" $fichier = "\\*****\3-Clients\3-Run\Manpower\TSD\MPW - Nettoyage disque .ps1" $LWTSERVER = Get-childitem "\\*****-\3-Clients\3-Run\TSD\MPW - Nettoyage disque .ps1" $liste| foreach { $items = $_.split(",") } foreach ($item in $items){ Start-Sleep 3 [String]$path = "\\$item\c$" [string] $destination = "k:\Temp\Nettoyage disque" write-host "$item marche bien" New-PSDrive –Name “K” –PSProvider FileSystem –Root “$path” –Persist write-host "\\$path est le chemin" if (!(test-path -path $destination)) { New-Item $destination -ItemType directory Copy-Item -path $fichier -Destination $destination -recurse -force Remove-PSDrive -Name k -ErrorAction Continue } else { $presence = test-path -Path 'K:\Temp\Nettoyage disque\MPW - Nettoyage disque .ps1' if ($presence -eq "true") { $LWTPC = Get-ChildItem -Path "K:\Temp\Nettoyage disque\MPW - Nettoyage disque .ps1" if ($lWTPC.lastwritetime -lt $LWTSERVER.lastwritetime){ Remove-Item -Path "k:\Temp\Nettoyage disque\MPW - Nettoyage disque .ps1" Copy-Item -path $fichier -Destination $destination -recurse -force Remove-PSDrive -Name k -ErrorAction Continue }else{ write-host "fichier sur le poste, plus récent, pas de copie" Remove-PSDrive -Name k -ErrorAction Continue } Remove-PSDrive -Name k -ErrorAction silentlyContinue } } } Remove-PSDrive -Name k -ErrorAction SilentlyContinue
[\pre]
It works for maybe 15 computers, and then i only get the error for every item.
I don’t know what to do, can someone give me a hint?
Thanks