Last active
December 20, 2018 21:44
-
-
Save nshores/25d06f70d12c03908557264bbf51cb80 to your computer and use it in GitHub Desktop.
vm-dns.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$iplist = import-csv /Users/nshores/Documents/USA Properties/vms122018.csv | |
$guestcred = Get-Credential | |
$CompCollection=@() | |
$code = @' | |
$dns = Get-NetIPConfiguration | Select-Object -ExpandProperty DnsServer | select ServerAddresses | |
$dns.serveraddresses | |
'@ | |
foreach ($machine in $iplist){ | |
$network = get-vm $machine.name | Invoke-VMScript -GuestCredential $guestcred -ScriptType powershell -ScriptText $code | |
$Dnsout = $Network.ScriptOutput | |
#define custom object | |
$CompCurrent = New-Object -TypeName psobject | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name ComputerName -Value "" | |
$CompCurrent | Add-Member -MemberType NoteProperty -Name DNSSettings -Value "" | |
#populate custom object | |
$CompCurrent.computername = $machine.name | |
$CompCurrent.DNSSettings = $dnsout | |
$CompCollection += $CompCurrent | |
#write-host "Machine - $machine `n" | |
#write-host "DNS - $dnsout`n" | |
} | |
$CompCollection | export-csv -NoTypeInformation dns_list.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment