Aston-HyperV-Code/Memo.ps1

42 lines
1.7 KiB
PowerShell
Raw Normal View History

2021-04-21 15:00:09 +02:00
#$VMNetAdap = Get-VMNetworkAdapter -VMName RTR-01|ft -Property Switchname,Macaddress -HideTableHeaders
Get-VMNetworkAdapter -VMName RTR-01|Format-Table -Property Switchname,Macaddress -HideTableHeaders |Export-Csv D:\scripts\Guests\MACS\test.csv -NoTypeInformation
#echo $VMNETADAP | out-file -FilePath D:\scripts\Guests\MACS\temp.txt
$IP = "10.10.10.10"
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$Gateway = "10.10.10.1"
$Dns = "10.10.10.100"
$IPType = "IPv4"
# Retrieve the network adapter that you want to configure
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
# Remove any existing IP, gateway from our ipv4 adapter
If (($adapter | Get-NetIPConfiguration).IPv4Address.IPAddress) {
$adapter | Remove-NetIPAddress -AddressFamily $IPType -Confirm:$false
}
If (($adapter | Get-NetIPConfiguration).Ipv4DefaultGateway) {
$adapter | Remove-NetRoute -AddressFamily $IPType -Confirm:$false
}
# Configure the IP address and default gateway
$adapter | New-NetIPAddress `
-AddressFamily $IPType `
-IPAddress $IP `
-PrefixLength $MaskBits `
-DefaultGateway $Gateway
# Configure the DNS client server IP addresses
$adapter | Set-DnsClientServerAddress -ServerAddresses $DNS
2021-04-21 15:00:09 +02:00
Get-VMNetworkAdapter -VMName "Virtual 2008 1" | Where-Object -Property MacAddress -eq "00155D647100" | Rename-VMNetworkAdapter -NewName "vNIC1"
Get-NetAdapter |Where-Object {$_.MacAddress -eq 'XX-XX-XX-XX'} | Select-Object`
-Property Name | Format-Table -HideTableHeaders
2021-04-21 16:02:07 +02:00
$adapts = Get-NetAdapter
foreach ($adapt in $adapts) {
$HWName = (Get-NetAdapterAdvancedProperty -name $adapt.name -DisplayName "Hyper-v Network Adapter Name").DisplayValue
Rename-Netadapter -name $adapt.name -NewName $HWName
}