Reputation: 183
Hi all,
I am a beginner with powershell. I created a MyPoweshell.ps1 file as follows:
MyFunction1
MyFunction2
Function MyFunction1 {
}
Function MyFunction2{
}
1) When creating a .cmd file to run the script nothing seems to work except if I typed in the cmd console: Import-Module .\MyPoweshell.ps1. But if I save that code in .cmd and double click the cmd it immediately close. How to run powershell from cmd by double click on it without closing the screen ?
2) Trying to make a clickable shortcut that shows in .cmd but nothing works. Example : C:...\Program Files\MyFolder. How to create a clickable shortcut ?
I appreciate any help. Thanks.
Upvotes: 0
Views: 636
Reputation: 5871
You are trying to call a powershell function from CMD? See whats wrong here?
To call a powershell script from CMD enter the following:
powershell -file C:\yourscript.ps1
Also you need to define the functions before you call them so in yourscript.ps1 you would need to have this
Function MyFunction1 {
# Do Stuff
}
Function MyFunction2{
# Do Stuff
}
MyFunction1
MyFunction2
Upvotes: 2