the module is at http://gallery.technet.microsoft.com/scriptcenter/1abd77a5-9c0b-4a2b-acef-90dbb2b84e85
when i run a script which uses the get-ace cmdlet in a Windows Powershell enviroment and finishes, exit it using ctrl-c or using exit command in the script, i have to restart my Powershell environment to use my script again. Otherwise i end up getting errors that it doesn't know what get-ace is. yet during the whole time the script runs for the first time, it can run for days and finish fine.
any ideas on what the issue is?
Related
I have a powershell script, that starts x number of Jobs. If I start it from powershell, the processes stays alive, but if start from cmd, after the script finishes every process stops.
The only way I can keep the processes alive, is to put Sleep in the script. Why is that?
This is how I start the script from cmd:
Powershell.exe .\scripts\cpu_load.ps1 -UtilizeCorePercent 50
The PowerShell.exe has 2 main modes of operations.
A terminal mode where you can run multiple scripts or individual commands.
An execution mode where PowerShell.exe starts running, it then executes a script that was passed to it as a parameter, continues to run until the script exits, and then the PowerShell.exe exits or closes.
In terminal mode, variables you assign, jobs you start, and more, will stay active and available until you exit the PowerShell.exe terminal. Similarly, in execution mode, everything remains available until the script exits - which exits the PowerShell.exe.
The CMD terminal allows you to execute exe programs such as Notepad.exe and PowerShell.exe, but you have to understand that CMD.EXE is, itself, an executable program ran typically by a shortcut placed somewhere in your Windows Desktop.
The fact that CMD is its own exe program means that it has no "awareness" of any type of other exe programs, and, as such, it will not preserve anything from those other exe programs after they close.
The only solutions is something similar to iRon's comment on using "Wait-Job and/or Receive-Job", where, in some fashion, PowerShell.exe remains running until the job(s) are done.
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 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.
I am loading Powercli snapin in my script. If i execute a script first time in a session it takes more time. When i am executing another script which uses the same snapin ,it takes less time.[I measured the performance using Measure-Command cmdlet]
So i think whenever new session is created , it takes more time to execute the script.
In our case , as users will execute powershell by right clicking the file and run with powershell it will always run in new session. So every time they are facing slowness.
Why executing the powershell script first time in a session takes much time?
Is there any way to avoid this slowness? [I am using Powershell 2.0]
You're loading the snap-in. When you run your script the second time in the same session it is already loaded so Add-PSSnapIn returns quickly as it notices there is nothing to do.
If you want to always load the snap-in, yu can do so in your profile. Simply do
notepad $profile
in PowerShell and append the Add-PSSnapIn call.
I have a TFS Build where I run PowerShell script. The problem is PowerShell.exe never stops after runnig and do nothing.
Script is signed by trusted sertificate and successfully runs on my BuildAgent from PowerShell and writes logs. But it don't to anything from build or from cmd.exe. PowerShell.exe just starts and do nothing.
P.S. PS script have Exit commands but it not help.
Thanks,
Roman
You can use, Stop-Process -Id $PID from within the script to end the current PowerShell process.
The issue was resolved.
Problem was security settings on BuildAgent. When I run script manually from BuildAgent user's account and choose "Run always" build starts working correctly.