Support Forums

Full Version: PowerShell Hotfix List Script - Created by Ace
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here's a simple script I created for PowerShell just a few minutes ago:
Code:
$strCreator = "Ace"
$strURL = "http://www.techlifeforum.net"

$HotFix_ = Get-Hotfix | write-output
foreach ($objItm in $HotFix_) {
    write-host
    write-host Hotfix ID - $objItm.HotFixID -foregroundcolor "magenta"
    write-host . Description: $objItm.Description -foregroundcolor "gray"
    write-host . Installed By: $objItm.InstalledBy -foregroundcolor "gray"
    write-host . Installed On: $objItm.InstalledOn -foregroundcolor "gray"
}
write-host

write-host ----------------------------------------------- -foregroundcolor "white"
$Date_ = Get-Date
write-host Current Time: $Date_ -foregroundcolor "magenta"
write-host Script Created by $strCreator "(c)" 2011 -foregroundcolor "white"
write-host Visit: $strURL -foregroundcolor "white"
write-host ----------------------------------------------- -foregroundcolor "white"
write-host

If you have Windows7, PowerShell will be built into your system by default, whereas older versions of Windows you needed to install this manually, if you cant run unsigned scripts, you'll have to turn that on. Especially if you're new to PowerShell and you're running it for the first time.

Basically i'm parsing data out of two codelets already built into PowerShell.
-Get-Hotfix
-Get-Date

Although Get-Date is already formatted, so I didn't need to do anything with that except give it a value as a variable to show it as a string with write-host which basically gives everything it's color eyecandy in short Smile

Along with "-foregroundcolor " there's also a backgroundcolor identifier, but I didn't feel like making things too stressful on the eyes.

The 2 variables at the top just gives you easier access to change that, even though I hope someone, (if they do decide to change them) will give credits to me as I wrote this script myself.

[Image: iqSFJMuj.png]

The loop here assigns values to my items:
Code:
foreach ($objItm in $HotFix_) {
    write-host
    write-host Hotfix ID - $objItm.HotFixID -foregroundcolor "magenta"
    write-host . Description: $objItm.Description -foregroundcolor "gray"
    write-host . Installed By: $objItm.InstalledBy -foregroundcolor "gray"
    write-host . Installed On: $objItm.InstalledOn -foregroundcolor "gray"
}

Get-Hotfix will display every last one of those items in it's built in function if you let it be, but by taking them out myself I can rearrange them in whatever order I want.

To get the values of each item value you are trying to parse out, they usually make it easy for you by placing the titles of those values at the top in the menu. One that I felt wasn't needed in this case was "Source" so that isn't included in this script.

If you want it added all you'd need to do is define it with $ObjItm.Source in the foreach loop to make sure that it parses all of it's values everytime it loops through a hotfix and scans for information to piece out.

Example Line: (If you don't understand)
Code:
echo $ObjItm.Source

Or use write-host again if you want to use colors, and make sure you define either a forground or background color in quotes.
I haven't got a clue what any of this is but it look very complex and interesting lol.

Good job? I think? Smile
(08-16-2011, 11:37 AM)Skream Wrote: [ -> ]I haven't got a clue what any of this is but it look very complex and interesting lol.

Good job? I think? Smile

PowerShell is very advanced in comparison to command prompt to give you an idea. It basically gives you access to anything that your programs can do on your computer, and it will let you execute your programs with a debug write and various other built in debug functions, as well as functions for various GET methods as well including your installed hotfixes (as shown here), running services, processes, and full control over all of that as well.

You can write scripts to do multiple tasks with the use of one function.
[yt]http://www.youtube.com/watch?v=to5LGaqXb6s[/yt]

Here's a video of my script in use
Learned how to do this in one of my classes at school =p Still a great release ^^ lol. Makes everything easier.
I'm actually going to compile this script into a full system information script, including the areas for a list of programs installed (I'll look through the keys in the registry to find installed programs), and various other things as well.
If you need to allow access to run scripts btw use this command in powershell:
Code:
set-executionpolicy remotesigned

To view your Current setting:
Code:
Get-ExecutionPolicy

And fragma, I didn't even realize that was you at first haha
(08-16-2011, 11:37 AM)Skream Wrote: [ -> ]I haven't got a clue what any of this is but it look very complex and interesting lol.

Good job? I think? Smile

Oh, for more clarification, hotfixes is a fancy word for your installed Windows update packages.