Kahn Kah
Kahn Kah

Reputation: 1463

Implementing validation and checks in Powershell script

So I currently have a Powershell script that installs various software silently

What I have at the moment are all of the commands which work perfectly:

Start-Process 'C:\Files\Install files\Firefox' -ArgumentList "/S" -Wait
Start-Process 'C:\Files\Install files\Office' -ArgumentList "/s" -Wait
Start-Process 'C:\Files\Install files\Zeb' -ArgumentList "/S" -Wait

What I now want to implement is 'checking if the installation is succeeded'.

I start the program by checking the install files:

Write-Host "Checking if install files are present..."
if(Test-Path 'C:\Files\Install files\')
{
Write-Host "Files located. Installation will begin"
Write-Host ""
} else
{
Write-Host "Files not located, please check the directory"
Write-Host ""
break
}

And since the code of above is working I thought that I could maybe to the same for installing my software? But using the software directory as a test-path function:

Write-Host "Installing Firefox"
Start-Process 'C:\Files\Install files\Firefox' -ArgumentList "/S" -Wait
if (Test-Path C:\Program Files(x86)\Firefox)
{
Write-Host "Firefox succesfully installed!"
}else
{
Write-Host "Error, FireFox hasn't been installed"
}

.... And continue like this for the other programs

I thought 'why not?' since all of the PC's are the same and I must admit that the code also works.

But how would someone would judge this method? And what are alternatives?

Thanks

Upvotes: 0

Views: 570

Answers (2)

Deadly-Bagel
Deadly-Bagel

Reputation: 1620

Just a note, I think this is more a question for Server Fault or Super User.

There are some high end tools like Desired State Configuration that handle all this but it really depends on the environment. We build standalone servers in an offsite datacentre and it's so much more convenient and less setup to just have a script that installs and configures everything that can't be imaged. Sure it takes two hours to complete but it's unattended, and since the OS is installed from a template we guarantee they're all exactly the same.

Perhaps I wouldn't recommend this method if the hardware were drastically different or if not imaging the OS to run the script on, I used to have a batch file to deploy customer desktops (back in WinXP days) but eventually cut it down to just detect the model and install drivers because it was too much hassle to maintain. I would also not recommend this method if it will be maintained by more than one person, or if the person maintaining it will be maybe/definitely not long term staff.

Overall it's up to the company. DSC is certainly a more professional and complete approach and much more easily maintained by multiple people, so put it to them and if they won't devote resources for a deployment server and training then you don't have much choice either way.

Upvotes: 2

Walhalla
Walhalla

Reputation: 396

I would recommend to have a look at something more professionell like "PowerShell App Deployment Toolkit". (http://psappdeploytoolkit.com/) It will take some time for you to start, but it is not that complex. It outputs logs and so on.

Upvotes: 1

Related Questions