-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigure-LabVM.ps1
More file actions
35 lines (31 loc) · 1.44 KB
/
Configure-LabVM.ps1
File metadata and controls
35 lines (31 loc) · 1.44 KB
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
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
[string]$LabName,
[Parameter(Mandatory = $true)]
[string]$VMHostname,
[Parameter(Mandatory = $true)]
[string]$Username,
[Parameter(Mandatory = $true)]
[string]$Password,
[Parameter(Mandatory = $true)]
[string]$IPAddress,
[Parameter(Mandatory = $true)]
[int]$PrefixLength,
[Parameter(Mandatory = $true)]
[string]$DefaultGateway,
[Parameter(Mandatory = $true)]
[string[]]$DNSServer,
[Parameter(Mandatory = $true)]
[string]$TimeZoneID
)
$VMName = "$LabName-$VMHostname"
$SecurePassword = ConvertTo-SecureString -String $Password -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList ($Username, $SecurePassword)
$Session = New-PSSession -VMName $VMName -Credential $Credential
Invoke-Command -Session $Session -ScriptBlock {Rename-Computer -NewName $using:VMHostname -Restart}
Start-Sleep -Seconds 30
$Session = New-PSSession -VMName $VMName -Credential $Credential
Invoke-Command -Session $Session -ScriptBlock {New-NetIPAddress -InterfaceAlias Ethernet -AddressFamily IPv4 -IPAddress $using:IPAddress -PrefixLength $using:PrefixLength -DefaultGateway $using:DefaultGateway}
Invoke-Command -Session $Session -ScriptBlock {Set-DnsClientServerAddress -InterfaceAlias Ethernet -ServerAddresses $using:DNSServer}
Invoke-Command -Session $Session -ScriptBlock {Set-TimeZone -Id $using:TimeZoneID}