I am having a little difficulity trying to do something.
- I am running a command that checks the DNS Conditional Forwarders, ANDexports the results to a CSV.
- create a variable and import the contents of the csv
- have a if statement that if the variable is $null to create/add data to the csv file so it is not null.
Here is what I came up with:
gwmi -Namespace root\MicrosoftDNS -Class MicrosoftDNS_Zone -Filter "ZoneType = 4" |
foreach {
foreach ($server in $_.masterservers) {
new-object -type psobject -prop @{Name=$_.Name;MasterServer=$server}
}
} | Export-Csv "C:\temp\DNSZones.csv"
Start-Sleep -s 10
$DNSZonesCSVContent = import-csv "c:\temp\DNSZones.csv"
If ($DNSZonesCSVContent -like "$null") {
$CSVContent = @()
$row = New-Object System.Object
$row | Add-Member -MemberType NoteProperty -Name "Name" -Value "NA"
$row | Add-Member -MemberType NoteProperty -Name "MasterServer" -Value "NA"
$CSVContent += $row
$CSVContent | Export-CSV -Path "C:\temp\DNSZones.csv"
}
I can see that a empty csv is being created by the original command, and when I import it into the variable it doesn’t show anything (as expected). I also know that if I run the portion of the script that creates the array and exports it into the existing CSV it works fine when run all by itself (not in the if statement). I have tried using -eq, -like, -notlike, etc… against $null or * and still nothing happens.
What am I doing wrong?
Thanks,
Ed