Wednesday, February 4, 2009

PowerShell: Ensure Successful Build Installation

Here’s one problem statement. Let’s say, you have an application installed on multiple systems i.e.; more than 1 system. And you need to know, the files that get installed on these systems once you have installed the application. To top it, the application gets installed on either C: or D: How do you do this? In PowerShell it’s easy.

Code:
Disclaimer: I’m not responsible for any inadvertent consequences you face after running this script.
Below, ‘test’ is the folder where the application gets installed.
FileName: Files-AfterInstall.ps1

foreach ($computer in $args)
{
"-----------------" | out-file BuildInstalled.txt -append
"$computer" | out-file BuildInstalled.txt -append
"-----------------" | out-file BuildInstalled.txt -append

if ((Test-Path -path \\$computer\c$\test) -ne $True)
{}
else
{
get-childitem -recurse \\$computer\c$\test -include *.* | foreach-object {$_.FullName} | out-file BuildInstalled.txt -append
}

if ((Test-Path -path \\$computer\d$\test) -ne $True)
{}
else
{
get-childitem -recurse \\$computer\d$\test -include *.* | foreach-object {$_.FullName} | out-file BuildInstalled.txt -append
}

}

Run as: .\Files-AfterInstall.ps1 system1 system2 (system1, system2 ... system n are the systems where build is installed)

Output:
As output, you would receive a file named BuildInstalled.txt which gets created where the script is running. This file would contain the full path of the files that get installed.

No comments: