Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PowerShell Hotfix List Script - Created by Ace
#1
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.
Reply


Messages In This Thread
PowerShell Hotfix List Script - Created by Ace - by AceInfinity - 08-16-2011, 11:35 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Batch] Quick Drive Information Script (Created by AceInfinity) AceInfinity 17 7,251 02-09-2012, 08:10 AM
Last Post: AceInfinity
  Ace's Total Cleaner AceInfinity 29 9,514 01-14-2012, 10:29 AM
Last Post: AceInfinity
  [GUI PowerShell] Get_UserACC - Get All User Accounts Info from WMI (Advanced Script) AceInfinity 4 2,312 01-06-2012, 05:22 PM
Last Post: AceInfinity
  TLF Diagnostic Tool - Created by Ace [Quick Preview] AceInfinity 0 862 08-26-2011, 06:06 PM
Last Post: AceInfinity
  Get Top 5 CPU Consuming Processes {PowerShell} AceInfinity 10 7,542 08-21-2011, 08:22 AM
Last Post: AceInfinity

Forum Jump:


Users browsing this thread: 2 Guest(s)