Skip to content

Instantly share code, notes, and snippets.

@nshores nshores/vm-dns.ps1
Last active Dec 20, 2018

Embed
What would you like to do?
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
You can’t perform that action at this time.