I've got the following code and have been trying to add an IF statement so that if the item is not found, write the text NotFound.
$csv1 = Import-Csv D:\MaintenanceWindow2.csv
$csv2 = Import-Csv D:\ScomAlerts.csv
$csv1 | Where {$field = $_.Computername;($csv2 | where {$_.Computername -eq $field})}
-Edit, here is what I currently have but it doesn't seem to pick every server.
Import-Csv D:\2.csv | ForEach-Object {
$table[$_.Computername] = $_.'Collection Name'}
$Global:result = $AlertDataNoDupe | ForEach-Object { [PSCustomObject] @{
Server=$_.NetbiosComputerName
MaintenanceWindow=IF($table[$_.NetbiosComputerName]){$table[$_.NetbiosComputerName]}
ELSE{"Not found!"}
}
-Edit, adding sample data
MaintenanceWindow2.csv:
"Computername","Collection Name"
"Server1","NA - All DA Servers - Patching - Cert - Thu 2:00"
"Server2","NA - All DA Servers - Patching - Cert - Thu 2:00"
ScomAlerts.csv:
ComputerName
Server2
Server3
Compare-Objectfor something like this. It will tell you the differences.Compare-Object $csv1 $csv2$hash = @{}does not seem to be needed.