Hello all, I am after some help/advice on some powershell writing.
I am trying to move our company away from GPP printers to a powershell script with csv lookup.
Numerous reasons but mainly GPP (on users) when mapping printers it can slow logins if a particular printer that a user/device maps is offline.
Base script so far
$csv = "C:\temp\printers.csv" $addprinters = Import-Csv $csv foreach ($Computer in $addprinters){ If ($Computer.pcname -eq $env:computername) { $Printers = ($Computer.printers).split(";") foreach ($Printer in $Printers) {Add-Printer -connectionname $Printer -ErrorAction SilentlyContinue} (New-Object -ComObject WScript.Network).SetDefaultPrinter("$($Computer.defaultprinter)") } }
CSV info
name, printers, defaultprinter X-Client-01, \\servername\printer1 X-Client-02, \\servername\printer1 Y-Client-01, \\servername\printer1 Y-Client-02, \\servername\printer1 Y-Client-01, \\servername\printer1 Y-Client-01, \\servername\printer2 Y-Client-01, \\servername\printer3
It doesn’t go as far as I would like to and now as tidy i am going in circles with it
I would prefer the device name to be condensed example if it was an if statement in vbs if(left(ucase(computername),9) = “Y-Client-”
So for example that any client that starts y-client- will be mapped the printer specified in the printers tab, then one step further so that multiple printers can be added to those devices or to a single device but based on just one line in the csv.
Example
X-Client-02 gets \server\printer1, \server\printer2, \server\printer3, with a default being \server\printer2
any device named like Y-Client- gets \server\printer4,\server\printer1,\server\printer6, default being \server\printer1
many thanks