Search This Blog

Saturday, November 23, 2013

Setting up a sheduled job to monitor software changes

Requirement:  To monitor software adds and deletes of software

Solution: Use a Powershell script to collect the installed software of both 32bit and 64bit applications, then take that script and schedule it to run weekly


1st the scripts to collect the software

32 bit

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* |  Select-Object DisplayName, DisplayVersion, Publisher, InstallDate

64 bit

Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate


Now take those scripts and create a scheduled job

32bit looks like

        $trigger = New-JobTrigger -DaysOfWeek Friday -Weekly -At 7PM

        $options = New-ScheduledJobOption -RunElevated

        $Filename32 = "32bitSoftware"

        Register-ScheduledJob -Name 32bitSoftware -ScriptBlock {
      
        Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
        Select-Object DisplayName, DisplayVersion, Publisher, InstallDate |
        Export-Csv ("c:\Jobs\"+ $Filename32 +"_"+ $((Get-Date).ToString('ddMMMyy')) +".csv") -NoTypeInformation} -Trigger $trigger -ScheduledJobOption $options

Note: for the 64 bit  replace the script block with the 64bit code, change the time, and change the filename variable

Friday, November 22, 2013

Great post from the Hey, Scripting Guy! Blog

Ran across this script on the  Hey, Scripting Guy! Blog

Use PowerShell to Remove Data from CSV File by Matt Tisdale


If you create a number of reports that have data not required for all end users this is a fast way to remove the columns that are not applicable to each user,  I know that it may be just as easy to create new reports for each users need, but if you are tasked with creating a report it may provide the data the user needs immediately as you work to capture the data the user may need 

Adding date stamp to filename using Powershell

The previous post was about adding the date stamp to files that were already created. This script would prevent you from having to do it again. If having the datestamp is necessary in the filename, why not put it in when you create the file.

The script below will save the date as you create the file

Get-Process | Export-Csv test_$((Get-Date).ToString('ddMMMyy')).csv

In this example test is the name of the file and $((Get-Date).ToString('ddMMMyy')) puts the the date after in the format of  Day Month Year

Output would look like test_22Nov13.csv

Note: You need to change the name "test" to something meaningful to the file being saved  or you could pass the variable to be saved.

$Filename = read-host "what would you like to call the file"
$Computername =  read-host "Which Computer"
Get-Process -ComputerName $Computername  | Export-Csv ($Filename.ToUpper() +"_"+ $((Get-Date).ToString('ddMMMyy')) +".csv")

Powershell to rename a group of files by adding the Created Date to the name.

If you have a need to add the date to a file name to help identify when it was created this script may have a use to to you.

It will search through a folder and rename a file by appending the date created to the original name of the file.

Get-ChildItem -Filter "*.csv" -Recurse | Rename-Item -NewName {$_.BaseName + $_.CreationTime.toString("ddMMMyy") + ".csv" }

Note:
The above script will only look for files in the path that you are currently in in powershell. 

Example of the output

original filename was something.csv

new filename  becomes something22Nov13.csv