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
Powershell

Avatar of undefined
Last Comment
String :-)
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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of String :-)
String :-)
Flag of Australia image

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
Avatar of String :-)
String :-)
Flag of Australia image

ASKER

Life saver. thanks champ
Powershell
Powershell

Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

27K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo