hi all,
First time posting and a new lover of powershel
We were asked to install printers using powershell (as it is faster then group policies) over the network.
In our organisation there a “number of printers” more then 50.
We are using the Location properties in the computer account in AD to allocate the printer to the computer (allocation based on location)
so based on the hostname of the local machine we find the location in the AD computer account and we can assign the printer.
being new to powershell I have charged ahead and created the script with the help of my friend TIM who is new to powershells as well.
But it will not run because we are using on of the AD cmdlet are not installed on the PCs about 1000. IS there away around this ?
Script:
/
$localcomputer = hostname
[Microsoft.ActiveDirectory.Management.ADComputer] $henry = Get-ADComputer -Identity $localcomputer -Properties location
[string]$str=$henry.location
$str
[array]$locations=$str.Split(“,”)
function AddPrinter {
param([string]$location)
$location
if($location -eq “$$$$$$$”){
Write-Host " \printservername\printername"; Add-Printer -ConnectionName “\printservername\printername”
}
if($location -eq "$$$$$$"){
Add-Printer -ConnectionName "\\printservername\printername"
}
}
if($str.Trim().Length -le 0){
#Default Case if no location set
Write-Host “Default:”
#Write-Host " \printerservername\printername"; Add-Printer -ConnectionName “\printerservername\printername”
}else{
foreach($location in $locations){
$location=$location.Trim();
if($location.Length -gt 0){
$tokens=$location.Split(“-”);
$campus=$tokens[0].Trim() +“-” +$tokens[1].Trim()
$campus=$campus.ToLower()
AddPrinter $campus
}
}
}
/