Powershell, get ip4v address of VM - Stack Overflow In a PowerShell script, how can I check if I'm running with administrator privileges? - Server Fault
function Get-VmIpAddresses ($VmName) {
get-vmnetworkadapter -vmname "$VmName" | % { $_.IpAddresses }
}
function Get-VmIpv4Address ($VmName) {
get-vmnetworkadapter -vmname "$VmName" | % { $_.IpAddresses } | ? { $_ -notmatch ":" } | select -first 1
}
## Get IPV4 and IPV6
"etidos" | % {
$baseName = $_ ; "app","data" | % {
$vmName = "$baseName$_" ; write-host $vmName ; Get-Vm-IpAddresses $vmName
}
}
## Alternate get IPv4 only
"etidos" | % {
$baseName = $_ ; "app","data" | % {
$vmName = "$baseName$_" ; write-host $vmName ; Get-Vm-IpAddresses $vmName | ? { $_ -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}' }
}
}
function Test-Administrator
{
$user = [Security.Principal.WindowsIdentity]::GetCurrent();
(New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
}