|
![]() |
#1 |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Hello world program with PowerShell
Can some one help me in writing a hello world program with PowerShell and execute it using NSIS. I have gone through this link but I am not able to understand clearly what needs to be done. http://nsis.sourceforge.net/PowerShell_support
I already have bunch of PowerShell scripts written, I would like to execute them too. |
![]() |
![]() |
![]() |
#2 |
Member
Join Date: Sep 2005
Location: Sitting next to my desk
Posts: 56
|
You need to call the powershell executable with the scritpname as parameter.
exec "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -file d:\mydir\myscript.ps1" But you should keep in mind on a 64 bit system there is a 32 bit and a 64 bit powershell installed. It may make a difference what powershell you are using depending on what the script is doing and if you are also using snapins, .... This signature is currently on vacation! |
![]() |
![]() |
![]() |
#3 | |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Quote:
PHP Code:
This is my PowerShell module script PHP Code:
|
|
![]() |
![]() |
![]() |
#4 |
Major Dude
Join Date: Feb 2007
Posts: 672
|
|
![]() |
![]() |
![]() |
#5 | |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Quote:
|
|
![]() |
![]() |
![]() |
#6 |
Member
Join Date: Sep 2005
Location: Sitting next to my desk
Posts: 56
|
Hello Chaitanyansis
In your case I'd try the followerd. I only explain how it could work, not the NSIS stuff. Assuming you have the followed ps1 script (do not use in this case psm1 since you need to use import-module. If you have a psm1 you shoudl handle this in the ps1 script you call. Script test.ps1: Param([Parameter(Mandatory=$False)][string]$param1="", [Parameter(Mandatory=$False)][string]$param2="") Write-host "Parameter: $param1 $param2" How to call the script from normal command prompt: powershell -file test.ps1 -param1 1 -param2 2 The result would be: Parameter: 1 2 This signature is currently on vacation! |
![]() |
![]() |
![]() |
#7 |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Hello th_mi,
I know how to execute a PowerShell script from command prompt but the thing is I have a requirement as follows. I will create a nsi dialog with some controls like text-boxes where user will enter value and submit so that on submit I need to execute the PowerShell script |
![]() |
![]() |
![]() |
#8 |
Member
Join Date: Sep 2005
Location: Sitting next to my desk
Posts: 56
|
exec "powershell.exe -file test.ps1 -param1 1 -param2 2"
Maybe you need the path to the ps1 file....!? This signature is currently on vacation! |
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Didn't worked
EXEC 'powershell.exe "& "C:\PowerShell\TestParameter.ps1 -param1 1"' |
![]() |
![]() |
![]() |
#10 | |
Member
Join Date: Sep 2005
Location: Sitting next to my desk
Posts: 56
|
Quote:
It worked as expected! This signature is currently on vacation! |
|
![]() |
![]() |
![]() |
#11 | |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Quote:
function CallMe { Param([Parameter(Mandatory=$False)][string]$param1="") Write-host "Parameter: $param1" } This is working fine Param([Parameter(Mandatory=$False)][string]$param1="") Write-host "Parameter: $param1" |
|
![]() |
![]() |
![]() |
#12 |
Member
Join Date: Sep 2005
Location: Sitting next to my desk
Posts: 56
|
You asked for a solution I gave one to you. If you don't like my solution it is up to you find a better one for you.
![]() This signature is currently on vacation! |
![]() |
![]() |
![]() |
#13 |
Junior Member
Join Date: Aug 2016
Posts: 14
|
Hi I am not saying that your solution didn't worked, but initially in my post I posted the code with function, so I am just checking to work it with like the requirement
|
![]() |
![]() |
![]() |
|
Tags |
powershell |
Thread Tools | Search this Thread |
Display Modes | |
|
|