DataGen/initialize-ComputerProjection.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
param ( [int]$count = 100, [switch]$whatif, [switch]$verbose, [switch]$progress, [string]$computerPrefix = "Computer", [string]$domain, [switch]$noBulk )

. ./Common.ps1

$userClass = get-scsmclass "^Microsoft.AD.User$" -verbose:$verbose
$userList = get-scsmobject $userClass -verbose:$verbose
$computerClass = get-scsmclass "^Microsoft.Windows.Computer$" -verbose:$verbose
$projectionType = get-scsmtypeprojection Microsoft.Windows.Computer.ProjectionType -verbose:$verbose
$Status = get-scsmenumeration System.ConfigItem.AssetStatusEnum.Deployed -verbose:$verbose
if ( $domain )
{
$DName = $domain
}
else
{
$DName = $env:userdomain
}
$ARGUMENTS = @{
    Type     = "Microsoft.Windows.Computer.ProjectionType"
    Whatif   = $whatif
    Bulk     = ! $nobulk
    Verbose  = $verbose
    }
$currentCount =0
2..$count | %{
    $CName = "${ComputerPrefix}{0:0000}" -f $_
    $PName = "${CName}.${DName}.net"
    if ( $progress )
    {
        $currentCount++
        $perc = [int](($currentCount/$count)*100)
        Write-Progress -Activity "Creating Instance" -Status $CName -Percent $perc
        if ( $currentCount -eq $count )
        {
            Write-Progress -Activity "Committing" -status "$count instances" -perc 100
        }
    }
    $seed = @{
        AssetStatus         = $Status
        DisplayName         = $PName
        IPAddress           = get-randomIPAddress
        IsVirtualMachine    = [bool]($RANDOM.Next(0,2))
        LastInventoryDate   = [datetime]::Now.AddDays(-($Random.Next(30,365)))
        NetbiosComputerName = $PName
        NetbiosDomainName   = $DName
        OffsetInMinuteFromGreenwichTime = $RANDOM.Next(0,24)*60
        PrincipalName       = $PName
        }
    $seedobj = new-scsmobject $computerClass -nocommit $seed -verbose:$verbose
    @{
        __CLASS          = "Microsoft.Windows.Computer"
        __OBJECT         = $seed
       # PhysicalComputer =
       OperatingSystem  = Get-OperatingSystem | %{
           @{
           __CLASS  = "Microsoft.Windows.OperatingSystem"
           __OBJECT = [hashtable]$_
           }
       }
       NetworkAdapter   = Get-NetworkAdapter | %{
           @{
           __CLASS  = "Microsoft.Windows.Peripheral.NetworkAdapter"
           __OBJECT = [hashtable]$_
           }

       }
       Processor        = Get-Processor | %{
           @{
           __CLASS  = "Microsoft.Windows.Peripheral.Processor"
           __OBJECT = [hashtable]$_
           }
       }
       PhysicalDisk     = Get-PhysicalDisk | %{
           @{
           __CLASS  = "Microsoft.Windows.Peripheral.PhysicalDisk"
           __OBJECT = [hashtable]$_
           }
       }
       LogicalDisk      = Get-LogicalDisk | %{
           @{
           __CLASS  = "Microsoft.Windows.Peripheral.LogicalDisk"
           __OBJECT = [hashtable]$_
           }
        }
        PrimaryUser      = Get-RandomItemFromList $userList
        Custodian        = Get-RandomItemFromList $userList
    }
} | new-scsmobjectprojection @ARGUMENTS