Running a powershell script - Advanced Installer Community

We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Arthur
Posts: 69
Joined: Wed May 19, 2010 9:53 am

Running a powershell script

Hi,

I'd like to run a Powershell script on Windows Server 2008. I'd like to check the status of FTPServer and enable it if isn't already enabled. I hope to use dism.exe to do this. Is this possible? I think I need to use a VBScript to start powershell, but I can't seem to get this to work.

Arthur
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Running a powershell script

Hi Arthur,
I'd like to run a Powershell script on Windows Server 2008. I'd like to check the status of FTPServer and enable it if isn't already enabled. I hope to use dism.exe to do this. Is this possible?
You can try to run your script in an elevated powershell cmd and there shouldn't be any trouble. The custom action that launches the powershell cmd will run as admin if you enable its "Deferred, with no impersonation" execution option.
I think I need to use a VBScript to start powershell, but I can't seem to get this to work.
Here is an article that may help you.

Best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Arthur
Posts: 69
Joined: Wed May 19, 2010 9:53 am

Re: Running a powershell script

Hi,

thanks for the reply. I enabled the "Deferred, with no impersonation" execution option as you suggested. I copied the code in the article. When I try running the script on the target system, with the ps1 file in the same folder, it works fine. When I try running it as part of the installer I get an error. The install logfile says script error -2146827788, Microsoft VBScript runtime error: Variable is undefined: 'WScript' Line 6, Column 1. I have the ps1 script installed in the Temp folder of the target machine. I've tried running the VBScript as an attached Custom Action , and as an Installed Custom Action, with the VBScript in the Temp folder. Same result each time. Any ideas?

Arthur
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Running a powershell script

Hi Arthur,

As I understood from the article both the vbscript and power shell script should have the same file name and placed in the same folder. Also, if you have copied them as temporary files you should make sure the custom action is placed after the CostFinalize standard action in hte InstallExecuteSequence.

If all above are fine and the script still doesn't work, please send us the VBS and PS1 files along with your AIP to support at advancedinstaller dot com so we can investigate them.

Best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Running a powershell script

Hi Arthur,

After looking into the VBScript a bit more closer, it seems it is calling a property of a WScript instance which is not supported in Windows Installer.

Here's what you can try, to make the script work with the installer:
  • in the Action Data field of your custom action you should have:

    Code: Select all

    "[#Enable.vbs]"
  • replace this script line from the VBS:

    Code: Select all

    appCmd = "powershell -noexit &'" & Replace(WScript.ScriptFullName, ".vbs", ".ps1") & "'"
    with this one:

    Code: Select all

    appCmd = "powershell -noexit &'" & Replace(Session.Property("CustomActionData"), ".vbs", ".ps1") & "'"
Best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Arthur
Posts: 69
Joined: Wed May 19, 2010 9:53 am

Re: Running a powershell script

Thanks Mihai, that worked.

Arthur
Arthur
Posts: 69
Joined: Wed May 19, 2010 9:53 am

Re: Running a powershell script

Hi,

When I run a powershell script in the way outlined here, the main thread of the installation does not wait on the script to finish, even though I have selected Synchronous execution, check return code as the Execution Property. Is there a way around this?

Cheers, Arthur
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Running a powershell script

Hi Arthur,

This is happening because your custom action launches the powershell script. From the Windows Installer perspective the custom action has finished and was successful. The process is not aware that the custom action actually triggered the powershell script so it will wait for it to complete as well.

To solve this, you should add code to your custom action which should wait for the powershell script to complete.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”