I am stuck in this weird problem where I am trying to execute a powershell script from the powershell command prompt. But neither do I get any errors nor the script is loaded.
I have script in C:\temp\myFunction.ps1 (which has a method getMyName() )
I open the powershell command and navigate to this directory and execute
./myFunction.ps1
then there are no errors and return back to the next line in the prompt. But when I try to call the function getMyName - I get error getMyName is not recognised.
I have set the Execution-Policy to Unrestricted, I am running the powershell as Administrator
Try dot sourcing your script:
. .\myFunction.ps1
It's basic problem of Powershell script. Set the Path where you physically saved your file and then execute the Powershell script. One more thing
1. start your command window run as admin.
2. set the Powershell script policy for execution.
Related
just for understanding this.
I want to open my Powershell in a certain folder. As I didn´t find out how, I tried to put a batch file with just "cd ....." in it in the default folder where PowerShell opens.
When I execute the batch, though, I end up where I started from.
It seems that the batch gets excuted in a subshell which doesn´t affect the Parentshell.
How can I execute the stuff in the batchfile in parentshell ?
Thanks in advance!
You cannot. Batch files are executed by cmd, not PowerShell, so there will always be a new process for them.
With a PowerShell script you can use dot-sourcing
. Script.ps1
To execute the script in your current scope, which is most similar to how batch files are executed by cmd by default.
If you want to open your Powershell in a certain folder, you can set that up in your Powershell profile. In Powershell, type $profile and that will give you the location of your profile file. Edit that file and use Set-Location:
Set-Location 'C:\Some\Place'
Powershell will execute whatever is in your profile script every time you open a new Powershell session.
I have a Powershell script which runs perfectly directly on my local machine using Powershell and command line. But when running in post-session command in Informatica, it is not getting executed, only the session gets succeeded. I am calling bat script using this command- $PMRootDir\Scripts\GetColumns.bat . And this bat script is further invoking Powershell script. Need help on this.
I tried running a build today and found that my command prompt is not able to execute powershell scripts. To confirm this, I created a test powershell script which simply writes to console. The script works fine when run from powershell, but is not recognizable by the command prompt. Screenshots below.
test script working from powershell
test script not working from command prompt
Any suggestions/explantion as to why this is happening?
Resolved it. I created a profile.ps1 script under ..\Documents\WindowsPowerShell folder to load custom settings for powershell. Removing profile.ps1 from the folder or adding a -NoProfile switch parameter solves this.
I'm trying to call a PowerShell script from another PowerShell script. The script I'm trying to call is in a subfolder named "Release" of the current directory.
I tried the following command but get an 'file not found' error from the PowerShell console.
."..\Release\out-datatable.ps1"
I have solved this by simply change to the subdirectory.
I wrote the following command to my script
cd Release
. .\out-datatable.ps1
Does anyone know how to execute a PowerShell script from SSIS? I have created the script and it works from from the command line. The script takes a couple of command line parameters, which work fine when called from cmd.exe.
I'm using an Execute Process Task in SSIS and cannot get the script file to execute. I'm using expressions to pass in the name of the script and the command line arguments. The task is returning an incomplete string token error.
From VS to launch PSH with an extra script (for a Cmdlet project) I use the following commandline:
powershell -noexit -command ". ./Startup.ps1"
The -noexit will keep the instance around (so you wouldn't want that), putting all the real commands in a script to be dot-sourced avoids a really long command line.
Go to Execute Process Task Editor -> Process tab and set the following options:
Executable - C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments - -File ".\PowershellScript/ps1" "arg_1_value" "arg_2_value" ... "arg_n_value"
Refer to the below screenshot: