-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-NetworkPrinterNamesAndServer.ps1
More file actions
31 lines (24 loc) · 1.17 KB
/
Copy pathUpdate-NetworkPrinterNamesAndServer.ps1
File metadata and controls
31 lines (24 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Import CSV file to be used for this script
$printerImport = "CSV\PATH\HERE.CSV"
$csvImport = Import-CSV -Path $printerImport
# Specify old and new print server details
$oldPrintServer = "oldprintserver"
$newPrintServer = "newprintserver"
# Run through and check old printers and update
Import-Csv -Path $printerImport | ForEach-Object {
# Define registry paths
$oldPrinterKey = "HKCU:\Printers\Connections\,,$oldPrintServer,$($_.oldPrinterName)"
$newPrinterKey = "HKCU:\Printers\Connections\,,$newPrintServer,$($_.newPrinterName)"
if (Test-Path -Path $oldPrinterKey) {
# Copies the old reg key to the new reg key destination with correct info
Copy-Item -Path $oldPrinterKey -Destination $newPrinterKey -Recurse -Force
# Updates the server key value to point to the new print server
Set-ItemProperty -Path $newPrinterKey -Name "Server" -Value "\\$newPrintServer"
# Remove old registry path
Remove-Item -Path $oldPrinterKey -Recurse -Force
# Deliver some output
Write-Output "Registry keys updated successfully."
} else {
Write-Output "Old registry key not found. No changes made."
}
}