pushd C:\Users\a.warme\Documents\ # my temp dir # read in file as an array to compare to in nagios config $nagios = Get-Content -Path C:\ew-nagios\prod\etc\nagios\local\hostgroup-accesspoints.cfg -raw # start scanning the file for matches to file entries from export of prod nps clients $nps = Get-Content -Path C:\Users\a.warme\Documents\nps_cleanup\rej-p-rad002_nps.txt #build custom object with ip, name , and found status $result = foreach($line in $nps) { if($line -match 'Name *= (.*)') { $obj = [pscustomobject]@{ IP = '' Name = $Matches[1] Found = '' } Write-Verbose -Verbose "'$line' matches Name - $($Matches[1])" } #put matches into object elseif($line -match 'Address *= (.*)') { $obj.IP = $Matches[1] $obj.Found = $nagios -match $obj.IP Write-Output $obj Write-Verbose -Verbose "'$line' matches Address - $($Matches[1])" } else { Write-Verbose -Verbose "'$line' has no match" } } #for grid view use #$result | Out-GridView #bulding a template for nagios hostgroup $template = @' define service {{ hostgroup_name AccessPoints service_description {0}-{1} use thales-service check_command check_ap!{2} check_interval 15 max_check_attempts 3 retry_interval 1 servicegroups spoc-monitoring,system-monitoring }} '@ #matching with not found adress and ip $notFound = $result | Where found -eq $false #insert adress and ip into template $output = foreach($obj in $notFound) { $template -f $obj.Name, $obj.IP, $obj.IP } #copy clipboard into hostgroup-accesspoints.cfg , remember to check for # or wierd spaces $output | Set-Clipboard