In A previous post with some help i managed to come up with an if statement that would search through a table and match a machines OU and then write that to another csv file, hunky dory so far
$tbl = import-csv "\\global\europe\newcastle\Transfer\Test\offices.csv" -Delimiter "," $ComputerName = $env:COMPUTERNAME $searcher = New-Object System.DirectoryServices.DirectorySearcher($root) $searcher.Filter = "(&(objectClass=computer)(name=$ComputerName))" [System.DirectoryServices.SearchResult]$result = $searcher.FindOne() if (!$?) { return } $dn = $result.Properties["distinguishedName"] $ouResult = $dn.Substring($ComputerName.Length + 4) if ($ValueOnly) { $ouResult } $Serial = gwmi win32_bios | select Serialnumber -ExpandProperty Serialnumber foreach ($row in $tbl) { if ($ouResult -like $row.pattern) { $serial | Export-Csv $row.destination -NoTypeInformation -append break } }
Now my issue is what if something falls outside of the $tbl variable? i would like to append it once to another file
else ($ouResult -notlike $row.pattern) { $serial | Export-Csv c:\tmp\misc.csv -NoTypeInformation -append break }
however this will match & write however many items that is in the csv that does not meet the criteria and i end up with the data x amount of times written to the same file. (also happens if it does find a match in the first part of the foreach for any rows it does not match)
example of csv
Pattern, Destination
OU=#London Campus, \global\europe\Transfer\Newcastle\Test\London Campus.csv
OU=Adelaide, \global\europe\Transfer\Newcastle\Test\Adelaide.csv
OU=Amsterdam, \global\europe\Transfer\Newcastle\Test\Amsterdam.csv
OU=Auckland, \global\europe\Transfer\Newcastle\Test\Auckland.csv
appreciate any help guys
Thanks