DataGen/Initialize-Printer.ps1

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
32
33
34
35
param ( $count = 10, [switch]$whatif, [switch]$verbose, [string]$prefix = "Printer",[switch]$nobulk )

. ./Common.ps1

$Printer = get-scsmclass Microsoft.AD.Printer -verbose:$verbose
$computerClass = get-scsmclass "^Microsoft.Windows.Computer$"
$computerList = get-scsmobject $computerClass -verbose:$verbose

$PARGS = @{
    Class   = $printer
    Bulk    = ! $nobulk
    Whatif  = $whatif
    Verbose = $verbose
    }

1..$count | %{  
    $computer = get-randomitemfromlist $computerList
    $printername = "{0}{1:0000}" -f $prefix,$_
    $DistinguishedName = "\\{0}\{1}" -f $computer.principalname,$printername
    Write-Progress -Activity "Creating Printer" -Status $printername -Perc ($current++/$count*100)
    
    @{
        AssetNumber                  = [guid]::newguid().ToString()
        Description                  = Get-Lorem 20
        DisplayName                  = Get-Lorem 4
        DistinguishedName            = $DistinguishedName
        Fullname                     = $printername
        PrinterName                  = $printername
        ServerName                   = $computer.DisplayName
        ShortServerName              = $computer.Name
        UNCName                      = $DistinguishedName
        WhenChanged                  = [datetime]::Now.AddDays(-($RANDOM.Next(60,360)))
    }
}  | new-scsmobject @PARGS