Snippets/definition.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
90
91
92
93
94
95
$snippet = {
    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        [string]
        $Name,

        [Parameter(Mandatory)]
        [string]
        $DefaultVirtualizationEngine,

        [Parameter(Mandatory)]
        [AutomatedLab.IpNetwork]
        $MachineNetwork,

        [string]
        $VmPath,

        [int]
        $ReferenceDiskSizeInGB,

        [long]
        $MaxMemory,

        [string]
        $Notes,

        [switch]
        $UseAllMemory,

        [switch]
        $UseStaticMemory,

        [string]
        $SubscriptionName,

        [string]
        $DefaultLocationName,

        [string]
        $DefaultStorageAccountName,

        [string]
        $DefaultResourceGroupName,

        [timespan]
        $AutoShutdownTime,

        [timezoneinfo]
        $AutoShutdownTimeZone,

        [switch]
        $AllowBastionHost,

        [pscredential]
        $AdminCredential,

        [ValidateLength(1,10)]
        [string]
        $VmNamePrefix
    )

    $defParam = Sync-Parameter -Command (Get-Command New-LabDefinition) -Parameters $PSBoundParameters
    New-LabDefinition @defParam

    $PSDefaultParameterValues['Add-LabMachineDefinition:Network'] = $Name

    if (-not $VmNamePrefix)
    {
        $VmNamePrefix = $Name.ToUpper()
    }
    
    $AutomatedLabVmNamePrefix = $VmNamePrefix
    

    if ($SubscriptionName)
    {
        $azParam = Sync-Parameter -Command (Get-Command Add-LabAzureSubscription) -Parameters $PSBoundParameters
        Add-LabAzureSubscription @azParam
    }

    if ($MachineNetwork)
    {
        Add-LabVirtualNetworkDefinition -Name $Name -AddressSpace $MachineNetwork
    }

    if ($AdminCredential)
    {
        Set-LabInstallationCredential -Username $AdminCredential.UserName -Password $AdminCredential.GetNetworkCredential().Password
    }
}

New-LabSnippet -Name LabDefinition -Description 'Basic snippet to create a new labdefinition' -Tag Definition -Type Snippet -ScriptBlock $snippet -NoExport -Force