We help IT Professionals succeed at work.

Powershell - Help adding error checking to my script :-)

String :-)
String :-) asked
on
66 Views
1 Endorsement
Last Modified: 2018-12-11
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
Comment
Watch Question

String :-)Windows Engineer

Author

Commented:
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
CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
String :-)Windows Engineer

Author

Commented:
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
String :-)Windows Engineer

Author

Commented:
Life saver. thanks champ
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.