luanch a function inside a script under condition

hello

 i have a script

#begin script

......

.\function1.ps1

.\function2.ps1

.\function3.ps1

#End script

is it possible to prompt the user to ask him if he want to run function1 or not...

thank you

April 27th, 2015 2:57pm

Hi,

Use Read-Host to get input and then use an if test.

http://ss64.com/ps/read-host.html

http://ss64.com/ps/if.html

Free Windows Admin Tool Kit Click here and download it now
April 27th, 2015 3:05pm

Also those are not functions, they are powershell scripts. If they contain powershell functions you want to be able to use from your main script, you will need to either dot-source the scripts or define them in a script module.
April 28th, 2015 12:58am

$a = new-object -comobject wscript.shell 
$intAnswer = $a.popup(Ask any qeustion,0,Delete Files,4) 
If ($intAnswer -eq 6) { 
.\function1.ps1
}
Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 5:17am

Hi Zizou,

To create powershell popup, you can also refer to the script below:

$wshell = New-Object -ComObject Wscript.Shell -ErrorAction Stop $judge = $wshell.Popup("Do you want to run this script",0,"YesOrNo",48+4) if($judge -eq 6){ .\..ps1} if($judge -eq 7){ Write-Host "do nothing" }

To get more detailed information about the parameters in popup, please refer to this article:

http://powershell.org/wp/2013/04/29/powershell-popup/

If there is anything else regarding this issue, please feel free to post back.

Best Regards,

Anna Wang

April 28th, 2015 10:03pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics