Workstation & Server Audit Script V3
One thing I wish I had was more time to re-visit my old scripts and re-write them as I often look at my old script and it sends a cold shiver down my spine as I now know a better way of doing things.
As I was away for the weekend and had no internet connection I took my old Audit Script with me, I had a few personal objectives that I wanted to achieve by re-writing this code and I was also asked by a friend who has started to adapt the code into other formats.
So, this is version 3 of the script, you can see how much I have learnt recently as V1 of this script was over 1000 lines, V2 of this script was 847 and now with the new improved code it is a miniscule 459 lines
My main objectives for this version of the script were:
- Apply my newly learnt PS Skills to optimise the code
- Use a HTML format that worked in all browsers
- Make the code easy to follow
- Make the code easy for other people to produce similar reports of other systems
When you see the code and use the output I hope you will agree I have achieved each of these. The code now works with all browsers I have tested and is very easily customisable.
Check out a screenshot of the output below:
As before this script can be run in two modes, if you run it as it is you will produce an audit of your current machine or if you run it with a path to a text file it will read a list of server names and audit each machine saving a separate html file for each one.
The script can be downloaded from here. Enjoy !
<SMALL RANT> Someone took my last script and removed my name from the code and then posted it as their own code on a powershell site, whilst I do not mind people adjusting and re-using my code, in fact there is nothing better than seeing how other people use my code I would prefer that you at least make a reference to my site or me in your comments.
I have been under certain pressure to start charging for some of my code which I have resisted as I like contributing and making the life of my fellow admins easier, claiming my code as your own is just plain rude.</SMALL RANT>







about 4 months ago
Thanks for the new code Alan. Your work is greatly appreciated!
about 4 months ago
Awesome script as usual. Your contributions are appreciated.
about 4 months ago
Hi Alan
How to i make this run if my servers have different passwords? It seems to run just fine on the local box i have powercli installed on but when i add a list of stand alone windows hosts off my ESX box, it fails to run (these boxes have a different administrator password than the one i am on)
about 4 months ago
@Paolo
This is one of the things I was thinking about adding, how would you see it working, do all servers have the same credentials, would you prefer to pass the script a -username and -password parameter ?
Would you prefer to put the username and password in the text file next to each server ?
Would you prefer the script to prompt you for a username/passowrd if it doesnt have access to the server ?
Thanks
Alan
about 4 months ago
@Virtu-Al
Hi Alan,
We host development servers for a number of different teams here so the admin password is usually one of 3. We never keep it the same as our ESX password and my powercli resides on the VC host itself. It would be nice if the txt file could contain an admin password it could use (not sure about security there) or have it prompt for an Admin password and have it keep using it on each subsequent server until it requires it to be changed, then it can prompt for the new password
I can see huge value for this script because once i host the server, the developers put it on me to make sure their environment is ok and healthy. I usually have to RDP into these hosts and check logs weekly. If the script could somehow do what i’ve asked it would be pure gold. Also could it email the results as well (something like your Dailyreport does).
Keep up the fantastic job. Your scripts have made my day to day stuff go much smoother and even helped us find a problem in our VC logs we didn’t even know existed !
about 4 months ago
Thanks again Alan. A joy to see …
about 4 months ago
@DJLO
Thanks for the comment, im glad the Daily Report is working out ok for you, it has found a few issues for me too
Just a quick note to say that this is a PowerShell script not specific to PowerCLI although it can be used with PowerCLI to audit your windows VMs, I will work on the permissions side of things and see what I can come up with.
Thanks for your information, it is useful when progressing the script.
Alan
about 4 months ago
@Andy
@Chris
@dboftlp
Thanks for the kind comments
about 4 months ago
The ability to pass it username and password from the text file would be a GREAT feature to this script. I have used a couple other scripts that have done this. One script that i love, that would love to see your script replace is SYDI (http://sydiproject.com/) Patrick is a great guy, but he doesn’t have much time to update his script any more. I would love to see some of the same things in his script in yours. Many of the features are already there, but the ability to write out the file to a word document or generate an overview file is great in my environment.
Keep up the great work Alan.
app
about 4 months ago
Thanks for the great Script . Can we have a method where in we can have the output in a single HTML file and then mail it to a Specific EMail ID ? may be we can look at removing Error logs to reduce the size of the HTML File .
looking forward to many more great scripts from you !!
about 4 months ago
Hi Alan,
Just came across your site recently. In fact I book marked it in a blog post a few months back and then went to find it last week now that our new vsphere infrastructure is humming away. Your daily healthcheck script is awesome and I would like to thank you for that. It also showed us errors in our vSphere servers that we are now troubleshooting!
Since I’m just starting out with Powershell, VESI, I hope too that one day I can contribute a script as userfriendly and as powerful as yours! Thank you.
za_mkh
about 4 months ago
Great script Alan.
An absolutely perfect solution to WW’s latest Microsoft licence audit.
Hope all’s well.
James
about 4 months ago
@Aaron
Thanks for pointing me at that, its a great resource, I can certainly move whatever you need from there into this script, which areas do you find most useful ?
As for the word part, I can also do this as have created a word export script before but would prefer to get all the details in there first.
Thanks for your comments, i can see this being a great help.
Alan
about 4 months ago
@Sudharsan
Sure, shouldnt be a problem, only issue is that Outlook will not allow the expand part to work so it will be a very long file unless i attach a single html ? Would that be suitable ?! Thanks for the comment
about 4 months ago
@za_mkh
Thanks for taking the time to leave such a nice comment, this is exactly why I give my scripts away for nothing !
about 4 months ago
@UppyJC
Nice one James, hope all is well at WW, say Hi to all for me.
about 4 months ago
You can use this with any powershell script or command.
Get-Credential |
This will prompt you for your login and then run the commandlet or script as the new login
about 4 months ago
@Omarr
Thanks for the comment, I wonder if people could use this or would prefer an option to provide a different username/password for each server/workstation ?
Thoughts ?
about 4 months ago
@Omarr
It cut out the command that I had typed. It should read
Get-Credential | commandlet or script name
about 4 months ago
Wow…great script! Cant wait to dissect this and uncover all of the HTML goodness you’ve got going on here.
about 4 months ago
Hi Alan… Thanks for the great script, once again you have done yourself proud. I’ve run this again out entire server farm, 300+ boxes and will schedule it to run every week to keep it up to date. Everyone here thinks it’s awesome. Even got James using it.
Could I make a suggestion for the next version. When you run the script, could it include a switch to either run a list of servers, something like “Audit.ps1 -L serverlist.txt” and a switch to audit individual servers, something like “Audit.ps1 -S servername”. Just a thought.
about 4 months ago
@Cory
Thanks for the comment, hopefully you will find it very easy to use
about 4 months ago
@Rob P
Great idea mate, let me know if you need any more info in there too.
about 4 months ago
Hey, this is a great script! Ran it on a couple machines and really like the output/format. Did run into one small problem that I thought I should report — on certain machines I get a divide by zero error on line 296. I believe this is because of a Q: drive that is 0 bytes (it was created by the Microsoft AppV client).
about 4 months ago
@bwuch
Ahh yeah, I think i need to put a trap in for that one, thanks.
about 4 months ago
Yes , Attachement as a Single HTML file also would hold good since we can schedule it as per convenience . For that i think we might need to remove the Error logs part since error logs might increase the Size of the HTML File that is being atatched and most organizations would have restrictions on the attachment size. Thanks Again for the Great Script !!
@Virtu-Al
about 4 months ago
Hi Alan, could I suggest having the Computer Description on the ‘General’ section. Would be nice for us as the computer name isn’t always very helpful.
Cheers mate.
about 4 months ago
Great script!
A couple of changes I made when I used it in my environment:
1. Started with a ping check (using Win32_PingStatus) to make sure that the target computers are online
2. Added the following code to get software inventory on Windows 2003 servers where the Win32_Product had not been installed (code goes in the Else portion of the Win32_Product check):
$colApps = @()
$hklm = 2147483650
$key = “SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall”
$wmi = [wmiclass]“\\$Target\root\default:stdRegProv”
$subkeys = $wmi.EnumKey($hklm,$key)
foreach ($subkey in $subkeys.sNames){
#Filter out hotfixes
if ($subkey -notmatch “KB*”)
{
$appName = ($wmi.GetStringValue($hklm,”$key\$subkey”,”DisplayName”)).sValue
$appVersion = ($wmi.GetStringValue($hklm,”$key\$subkey”,”DisplayVersion”)).sValue
$appVendor = ($wmi.GetStringValue($hklm,”$key\$subkey”,”Publisher”)).sValue
$appInstalldate = ($wmi.GetStringValue($hklm,”$key\$subkey”,”InstallDate”)).sValue
#Format installation date if it exists
#Set a trap to catch exceptions thrown by ParseExact if date is not in the expected format
Trap {
continue
}
if ($appInstalldate)
{
$appInstalldate = [datetime]::ParseExact($appInstallDate,’yyyyMMdd’,$null).Date.ToShortDateString()
}
$objApps = New-Object System.Object | Add-Member NoteProperty Name $appName -PassThru | Add-Member NoteProperty Version $appVersion -PassThru | Add-Member NoteProperty Vendor $appVendor -PassThru | Add-Member NoteProperty “Install Date” $appInstalldate -PassThru
$colApps += $objApps
}
}
Write-Output “..Software (via registry)”
$MyReport += Get-CustomHeader “2″ “Software”
$MyReport += Get-HTMLTable $colApps
$MyReport += Get-CustomHeaderClose
Write-Output “..Software WMI class was not installed, used registry instead.”
about 4 months ago
@Lucas
Nice one, love it
about 2 months ago
Hi Alan,
Could you possibly add in the OS Build number in you next release ?
Have a great Christmas. Rob…
about 2 months ago
@Rob P.
Will do Rob, although you could add it yourslef, honestly the code is very easy to change !