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.
Related
I am trying to automate the restart process of some applications with the help of PowerShell.
Basically, my main goal is to execute this line within the script:
'passwordOfCommand' | .\mycommand restart
When I just paste it to the PowerShell command prompt it works fine. But when I add this line within the script (for example script.ps1 ) it does not work.
Is there any solution for that?
I have a powershell script that if I open Powershell (right click> run as administrator) and post the code it works just fine. However when I try to create a task in task scheduler, the script will not work. I am assuming I need to sign the powershell script. I searched for a fix and came up with a Command that uses "makecert" however when I try to run it I get" 'makecert' is not recognized as an internal or external command.
you can just use "-ExecutionPolicy Bypass" in the program task arguments.
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'm trying to have powershell create a folder for me and it works fine when I type it into the console. However, when I run the same command as a script, no folder is created and no error messages are supplied.
This is the line of code I am using.
new-item - path c:\test\ -name testfolder -itemtype directory
edit: I am on Windows 7
This should be a comment, but I cannot comment. There is definitely nothing wrong with that line of code. It runs on my machine, either from the terminal window or as a script. Because the code works for you at the terminal window but not when executing as a script my first guess is that your system may be configured to disallow powershell scripts. This is the default setting, and it will prevent a script file from executing but will not prevent commands typed at the prompt from working. Open a powershell session and type get-executionpolicy. If it returns "restricted" then you have found the culprit. This setting can be changed by opening an elevated powershell session (run as admin) and typing set-executionpolicy -executionpolicy RemoteSigned. Of course you should read about what those settings mean before changing them to determine what is best for your situation. For example the remotesigned option means that scripts originating from your machine will execute without a trusted signature, but external scripts will require a signature.
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.