08-16-2011, 11:35 AM
Here's a simple script I created for PowerShell just a few minutes ago:
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
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.
The loop here assigns values to my items:
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)
Or use write-host again if you want to use colors, and make sure you define either a forground or background color in quotes.
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
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.
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.