-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrintersRemapping.ps1
More file actions
24 lines (20 loc) · 892 Bytes
/
Copy pathPrintersRemapping.ps1
File metadata and controls
24 lines (20 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass -Force
#Define servers
$OldServer = "Oldserver.domain.com"
$NewServer = "Newserver.domain.com"
#Read network printers
$printers = get-WmiObject -Query "select * From Win32_Printer Where Network = 'True'" | Select-Object systemName, shareName, location
#Loop to check printers
foreach ($printer in $printers){
$printerName = $printers.shareName
$server = $printers.systemName
$loc = $printers.location.Substring(0,4)
$location = [int]$loc
if ($server -like "\\$oldserver"){ # if ($printerName -like "\\$oldserver\*" -and $loc % 2 -eq 1) if you need based on numbers change on own needs
$printers.Delete()
$newPrinterConnection = "\\" + $newserver + "\" + $printerName
Add-Printer -ConnectionName $newPrinterConnection
}
else{
write-host "x"
}}