r/PowerShell • u/MartianMoon • Jan 13 '20
Network Printer Driver Nuker - Deletes all network printers & their drivers, then remaps the printers
https://github.com/Justin-Lund/Printer-Remapper
221
Upvotes
r/PowerShell • u/MartianMoon • Jan 13 '20
3
u/Dsraa Jan 14 '20
Why Shure! I wanted to perfect it up a little more, as its a bit rough around the edges but I'll share the relevant snippet of powershell. There's a few ways to pare the results to get the desired result, so I'm sure this can probably be modified/perfected to fit your scenario:
$PrintSRV = Get-ADObject -LDAPFilter "(&(&(&(uncName=*)(objectCategory=printQueue))))" -properties *|Sort-Object -Unique -Property shortservername #| select distinguishedname, shortservername
$PrintSRV.Distinguishedname.Split(',')[-3]
$PCOU = Get-ADComputer "$env:ComputerName" -Properties *
$PCOU.Distinguishedname.Split(',')[-3]
foreach($srv in $PrintSRV){
if( $PCOU.Distinguishedname.Split(',')[-3] -like $SRV.Distinguishedname.Split(',')[-3]){
write-output "Server: $srv.shortServerName.split('=)[-3]"
$Prnlistbox = $srv | select shortservername, location
$Prnlistbox
[void] $listBox.Items.Add("Print Server:$srv.shortServerName.split('=')[1]")
}
#Else{Write-Output "No Match"}
}
Hope this gives some ideas.