Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
$iplist = import-csv /Users/nshores/Documents/USA Properties/vms122018.csv
$guestcred = Get-Credential
$code = @'
$dns = Get-NetIPConfiguration | Select-Object -ExpandProperty DnsServer | select ServerAddresses
foreach ($machine in $iplist){
$network = get-vm $ | 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 = $
$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.