Link to home
Start Free TrialLog in
Avatar of String :-)
String :-)Flag for Australia

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).AddDays(-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\CurrentVersion\Uninstall\*|
        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.csv" -NoTypeInformation
Avatar of String :-)
String :-)
Flag of Australia image

ASKER

PS - I am studying Powershell myself (half way through Month of lunches), so please add any comments that will help me learn for next time. Cheers
String
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Life saver. thanks champ