Msiexec in powershell (from a batch file)

by 97browng at 2013-02-19 03:42:10

Hi All,

I have been running a batch file for a little while which installs a specific piece of software on over 100 machines. We are now using appsense and in it you can use scripts however it has to be powershell.

I know very little about powershell and have been looking at it but get a little stumped. Below is the code I currently use for the batch file, can anyone help me convert this to a powershell script please. I am a very new user so am finding it very difficult to comprehend. I have taken some tutorials but am still stuck.

I have powershellgui installed on my machine and have been messing with that but cannot seem to get anywhere.

All help will be appreciated;

Code (Taken out some of the pauses etc…)

Kill Current Process
taskkill /IM PCIDSS_IE_Carina.exe /f

Install MSI
msiexec.exe /i "\filer1a\support\Carina PCI DSS\PCIDSS Setup.msi" /qi /norestart

Copy Files
COPY "\filer1a\support\Carina PCI DSS\Copy" "C:\Program Files\Carina" /y

Register DLL
cd C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319
regasm "C:\Program Files\carina\PCI_DSSClient.DLL" /unregister
regasm "C:\Program Files\carina\PCI_DSSClient.DLL" /codebase

Change Folder Permissions
"\filer1a\support\Carina PCI DSS\xcacls.exe" "C:\Program Files\Carina" /T /G Administrators:F System:F "CREATOR OWNER":F Users:F /Y

Start Process
start /d "C:\Program Files\Carina" PCIDSS_IE_Carina.exe


Finally I also need to include an exit code in the script so appsense can tell if it was successful or not.
by DonJ at 2013-02-19 04:55:20
You can use that code almost exactly as-is. Do your machines have PowerShell 2 or 3 installed? When you run into a BAT-style command that doesn’t work, how you deal with it depends on the PowerShell version. 3 is a bit easier than 2.

If you’ve run into a command that doesn’t work, happy to try and help you sort it out.
by 97browng at 2013-02-19 09:51:56
Thanks for that. So I have looked and I have the below now (I dont need to register the dll yet). Do these look correct to you (especially the folder permission one where I just want to change the permissiong for ‘users’ and not administrators etc…)?

Kill Task
taskkill /im PCIDSS_IE.exe /f

Install EXE
msiexec /i ‘\filer1a\support\Carina PCI DSS\PCIDSS Setup.msi’ /qn /norestart

Start Task
start "C:\program Files\Carina\PCIDSS_IE.exe"

Copy Files
copy-item "\filer1a\support\Carina PCI DSS\Copy*" "C:\program Files\Carina" -force -recurse

Folder Permissions
cacls.exe "C:\Program Files\Carina" /E /P Users:F

If these are correct where do I go from here? I know in .bat files I just save the text file to a .bat and then off we go. If I save in powershellgui it saves as a .ps1 file which I cannot seem to run (I have set the machine to unrestricted in powershell but still no luck).

Also in powershell can I just put these commands one after another and will they wait for each one to complete or do I have to type anything else.

And finally how can I get an exit code?

Thanks again for the help.
Gary
by AlexBrassington at 2013-02-19 11:23:43
Powershell is deliberately a bit more tricky to run scripts in. The old school VBS and batch script model is a massive security risk.

To run a powershell script you can use something like the following:

powershell.exe C:\Folder\PowerShellFile.ps1

Powershell normally executes in sequence, there’s a always exceptions but the general rule is that each line must complete for the next to begin.
by DexterPOSH at 2013-02-24 19:42:29
When I was trying to run executables in my PowerShell Scripts,

I found this great resource llink:
http://social.technet.microsoft.com/wik … ables.aspx

Hope this is helpful.
Regards
~Dexter~