Skip to content

Instantly share code, notes, and snippets.

@nshores
Last active December 20, 2018 21:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshores/25d06f70d12c03908557264bbf51cb80 to your computer and use it in GitHub Desktop.
Save nshores/25d06f70d12c03908557264bbf51cb80 to your computer and use it in GitHub Desktop.
vm-dns.ps1
$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