by 97browng at 2013-02-19 03:42:10
Hi All,by DonJ at 2013-02-19 04:55:20
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
msiexec.exe /i “\filer1a\support\Carina PCI DSS\PCIDSS Setup.msi” /qi /norestart
COPY “\filer1a\support\Carina PCI DSS\Copy” “C:\Program Files\Carina" /y
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 /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.
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.by 97browng at 2013-02-19 09:51:56
If you’ve run into a command that doesn’t work, happy to try and help you sort it out.
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…)?by AlexBrassington at 2013-02-19 11:23:43
taskkill /im PCIDSS_IE.exe /f
msiexec /i ‘\filer1a\support\Carina PCI DSS\PCIDSS Setup.msi’ /qn /norestart
start "C:\program Files\Carina\PCIDSS_IE.exe"
copy-item “\filer1a\support\Carina PCI DSS\Copy*” “C:\program Files\Carina” -force -recurse
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.
Powershell is deliberately a bit more tricky to run scripts in. The old school VBS and batch script model is a massive security risk.by DexterPOSH at 2013-02-24 19:42:29
To run a powershell script you can use something like the following:
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.
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.