-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAzLocalVMConfigure.ps1
More file actions
57 lines (45 loc) · 3.55 KB
/
AzLocalVMConfigure.ps1
File metadata and controls
57 lines (45 loc) · 3.55 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$VMName = "myvmhostname"
$IPAddress = "192.168.1.3"
$PrefixLength = 24
$DefaultGateway = "192.168.1.1"
$DNSServer = "192.168.1.2"
echo "Parameters"
echo "VMName =" $VMName
echo ""
$Node1macNIC1 = Get-VMNetworkAdapter -VMName $VMName -Name "NIC1"
$Node1macNIC1.MacAddress
$Node1finalmacNIC1=$Node1macNIC1.MacAddress|ForEach-Object{($_.Insert(2,"-").Insert(5,"-").Insert(8,"-").Insert(11,"-").Insert(14,"-"))-join " "}
$Node1finalmacNIC1
$Node1macNIC2 = Get-VMNetworkAdapter -VMName $VMName -Name "NIC2"
$Node1macNIC2.MacAddress
$Node1finalmacNIC2=$Node1macNIC2.MacAddress|ForEach-Object{($_.Insert(2,"-").Insert(5,"-").Insert(8,"-").Insert(11,"-").Insert(14,"-"))-join " "}
$Node1finalmacNIC2
#$Node1macNIC3 = Get-VMNetworkAdapter -VMName $VMName -Name "NIC3"
#$Node1macNIC3.MacAddress
#$Node1finalmacNIC3=$Node1macNIC3.MacAddress|ForEach-Object{($_.Insert(2,"-").Insert(5,"-").Insert(8,"-").Insert(11,"-").Insert(14,"-"))-join " "}
#$Node1finalmacNIC3
#$Node1macNIC4 = Get-VMNetworkAdapter -VMName $VMName -Name "NIC4"
#$Node1macNIC4.MacAddress
#$Node1finalmacNIC4=$Node1macNIC4.MacAddress|ForEach-Object{($_.Insert(2,"-").Insert(5,"-").Insert(8,"-").Insert(11,"-").Insert(14,"-"))-join " "}
#$Node1finalmacNIC4
$cred = Get-Credential
echo "Credential Set"
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($Node1finalmacNIC1) Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $Node1finalmacNIC1} | Rename-NetAdapter -NewName "NIC1"} -ArgumentList $Node1finalmacNIC1
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($Node1finalmacNIC2) Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $Node1finalmacNIC2} | Rename-NetAdapter -NewName "NIC2"} -ArgumentList $Node1finalmacNIC2
#Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($Node1finalmacNIC3) Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $Node1finalmacNIC3} | Rename-NetAdapter -NewName "NIC3"} -ArgumentList $Node1finalmacNIC3
#Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($Node1finalmacNIC4) Get-NetAdapter -Physical | Where-Object {$_.MacAddress -eq $Node1finalmacNIC4} | Rename-NetAdapter -NewName "NIC4"} -ArgumentList $Node1finalmacNIC4
echo "MACs Renamed"
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Set-NetIPInterface -InterfaceAlias "NIC1" -Dhcp Disabled}
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Set-NetIPInterface -InterfaceAlias "NIC2" -Dhcp Disabled}
#Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Set-NetIPInterface -InterfaceAlias "NIC3" -Dhcp Disabled}
#Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Set-NetIPInterface -InterfaceAlias "NIC4" -Dhcp Disabled}
echo "DHCP Disabled"
#Set IP and Gateway within the strings
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($IPAddress, $PrefixLength, $DefaultGateway) New-NetIPAddress -InterfaceAlias "NIC1" -IPAddress $IPAddress -PrefixLength $PrefixLength -AddressFamily IPv4 -DefaultGateway $DefaultGateway} -ArgumentList $IPAddress, $PrefixLength, $DefaultGateway
echo "Static IP Set"
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {param($DNSServer) Set-DnsClientServerAddress -InterfaceAlias "NIC1" -ServerAddresses $DNSServer} -ArgumentList $DNSServer
echo "DNS Set"
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All }
echo "Hyper-V Enabled"
Invoke-Command -VMName $VMName -Credential $cred -ScriptBlock {Install-WindowsFeature -Name Hyper-V -IncludeManagementTools}
echo "Hyper-V Installed"