I am trying to deploy printers to the PCs in my organization through a powershell script. The script itself is deployed through group policy to run on machine startup. When a machine in the test OU boots it will sit at please wait indefinitely and the script never completes. The script works if you execute it manually. I won't go into the details of it but deploying printers directly through group policy is not an option.
Powershell Script
# Print File Server Path
$printsrv = "\\Servername\Deploy\"
# Check FTP Server Status
$file = ($env:computername + '.csv')
$num = 0
IF ((Test-Path ($printsrv + $file)) -eq $false) {
Do {
Start-Sleep -Seconds 5
$num = $num + 1
} Until ((Test-Path ($printsrv + $file)) -eq $true -or $num -eq 3)
}
if ((Test-Path ($printsrv + $file)) -eq $false) {exit}
# Create Printers
$print = Import-Csv ($printsrv + $file)
$num = 0
do {
(New-Object -ComObject WScript.Network).AddWindowsPrinterConnection($print.p_address[$num])
$num = $num + 1
} Until ($num -eq $print.Count)
#Set Default
$num = 0
Do {
$contains = $Print.Def_Bit[$num].Contains(1)
$Default = $print.P_Address[$num]
$num++
} until ($contains -eq $true -or $num -eq $print.Count)
(New-Object -ComObject WScript.Network).SetDefaultPrinter($Default)
Remove-Item -Path ($printsrv + $file)
Csv file
#TYPE System.Data.DataRow
"P_Address","DEF_Bit"
"\\server\printer",""
"\\server\printer","True"