String :-)
asked on
Powershell - Help adding error checking to my script :-)
Hi Experts..
I wonder if you could assist me to polish off my script below.
The idea is to audit Cisco AMP AV software across all servers in the domain. My 1st draft works OK, and provides the version installed on each server, however it is missing some important info as follows:
1. Some servers may need powered off, or my account may not have rights to query some servers in the domain, therefore is it possible to capture the PSComputerName and errors created in the output CSV?
2. Some servers may not have the software installed at all. Is it possble to add ""PsComputerName - Software not found"" in the output for these servers?
Many thanks for any tips, assistance. cheers String
My script so far:
$Output= @()
$DaysAgo=(Get-Date).AddDay s(-30)
$servers = (Get-ADComputer -SearchBase "OU=Services,DC=AD,DC=ACME ,DC=COM,DC =AU" -filter {(enabled -eq $True) -and (PwdLastSet -gt $DaysAgo) -and (LastLogonTimeSTamp -gt $DaysAgo)} | Where-Object {$_.DistinguishedName -notlike "*ou=Domain Controllers,*" -and $_.DistinguishedName -notlike "*ou=Non-Windows Servers,*" -and $_.DistinguishedName -notlike "*ou=Disabled Server Accounts,*" }).name
$sb = {Get-ItemProperty HKLM:\Software\WOW6432Node \Microsoft \Windows\C urrentVers ion\Uninst all\*|
Where-Object {$_.Publisher -eq 'Cisco Systems, Inc.' }
}
Invoke-Command -ComputerName $servers -ScriptBlock $sb |
Select-Object PsComputerName, DisplayName, DisplayVersion, Publisher, InstallDate | format-table | export-csv "D:\temp\CiscoAMP-Audit.cs v" -NoTypeInformation
I wonder if you could assist me to polish off my script below.
The idea is to audit Cisco AMP AV software across all servers in the domain. My 1st draft works OK, and provides the version installed on each server, however it is missing some important info as follows:
1. Some servers may need powered off, or my account may not have rights to query some servers in the domain, therefore is it possible to capture the PSComputerName and errors created in the output CSV?
2. Some servers may not have the software installed at all. Is it possble to add ""PsComputerName - Software not found"" in the output for these servers?
Many thanks for any tips, assistance. cheers String
My script so far:
$Output= @()
$DaysAgo=(Get-Date).AddDay
$servers = (Get-ADComputer -SearchBase "OU=Services,DC=AD,DC=ACME
$sb = {Get-ItemProperty HKLM:\Software\WOW6432Node
Where-Object {$_.Publisher -eq 'Cisco Systems, Inc.' }
}
Invoke-Command -ComputerName $servers -ScriptBlock $sb |
Select-Object PsComputerName, DisplayName, DisplayVersion, Publisher, InstallDate | format-table | export-csv "D:\temp\CiscoAMP-Audit.cs
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
LOL - I have to get up pretty early in the morning to catch you out oBdA ;-)
Yes nice script - works well - thanks a bunch.
Useful feedback for sure on the format *. Now I know why my script worked before I added the | export-csv bit. OK lesson learned - thanks
Lastly, I followed all parts of your script so thats progress for me. I like the use of Try, If, Catch and will try and incorporate that in my next one.
Thanks again
String
Yes nice script - works well - thanks a bunch.
Useful feedback for sure on the format *. Now I know why my script worked before I added the | export-csv bit. OK lesson learned - thanks
Lastly, I followed all parts of your script so thats progress for me. I like the use of Try, If, Catch and will try and incorporate that in my next one.
Thanks again
String
ASKER
Life saver. thanks champ
ASKER
String