powershell script to isntall printers

Home Forums Scripting PowerShell powershell script to isntall printers

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Avi
    Member
    #164405

    hi all,

    I have a Powershell script that we just wrote that install printers based on the location properties of the computer account in AD.
    the problem is that I am using an AD cmdlet and there for it will not run on the local PCS.

    We have about 50 printers and about 1000 pcs very little xp majority win 7 and some win 8 and about 40 locations, the idea is that installing printers via GPO takes at time about 10min. using the powershell will reduce it to about 2 min.

    If anyone has this problem of can contribute that will be great both me and my friend Tim are new to powershell :) ( and love it: )

    /
    $localcomputer = hostname
    $localcomputer = “dtwc1000”
    [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 ” \printservernameshareprintername”; Add-Printer -ConnectionName “\printservernameshareprintername”

    }

    if($location -eq “%%%%%”){
    Add-Printer -ConnectionName “\printservernameshareprintername”
    }
    }

    if($str.Trim().Length -le 0){
    #Default Case if no location set
    Write-Host “Default:”
    #Write-Host ” \printservernameshareprintername”; Add-Printer -connectionName “\printservernameshareprintername”
    }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
    }
    }
    }[/CODE][CODE]$localcomputer = hostname
    $localcomputer = “dtwc1000”
    [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 ” \printservernameshareprintername”; Add-Printer -ConnectionName “\printservernameshareprintername”

    }

    if($location -eq “%%%%%”){
    Add-Printer -ConnectionName “\printservernameshareprintername”
    }
    }

    if($str.Trim().Length -le 0){
    #Default Case if no location set
    Write-Host “Default:”
    #Write-Host ” \printservernameshareprintername”; Add-Printer -connectionName “\printservernameshareprintername”
    }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
    }
    }
    }[/CODE]

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.