Questions tagged [powershell]
PowerShell is a cross-platform command line and scripting utility from Microsoft. Use this tag for questions about writing and executing PowerShell scripts ONLY. Programming questions specific to the cross-platform version PowerShell Core (Windows, macOS, and Linux) should be tagged [powershell-core]. Questions about system administration should be asked on Super User or Server Fault.
powershell
118,120
questions
2897
votes
54
answers
4.7m
views
PowerShell says "execution of scripts is disabled on this system."
I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:
Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this ...
2871
votes
23
answers
3.1m
views
Determine installed PowerShell version
How can I determine what version of PowerShell is installed on a computer, and indeed if it is installed at all?
1365
votes
28
answers
3.7m
views
How can I close some specific port on Linux? [closed]
How can I remove the port that some application/process has used it but didn't close the port?
For example: when I run ssh on my ubuntu and tunnel the ssh connection on some port <PORT> on my ...
1103
votes
10
answers
1.0m
views
How do you comment out code in PowerShell?
How do you comment out code in PowerShell (1.0 or 2.0)?
1044
votes
17
answers
3.1m
views
How to run a PowerShell script
How do I run a PowerShell script?
I have a script named myscript.ps1
I have all the necessary frameworks installed
I set that execution policy thing
I have followed the instructions on this MSDN help ...
1004
votes
24
answers
1.2m
views
Setting Windows PowerShell environment variables
I have found out that setting the PATH environment variable affects only the old command prompt. PowerShell seems to have different environment settings. How do I change the environment variables for ...
972
votes
22
answers
2.4m
views
How do I concatenate strings and variables in PowerShell?
Suppose I have the following snippet:
$assoc = New-Object PSObject -Property @{
Id = 42
Name = "Slim Shady"
Owner = "Eminem"
}
Write-Host $assoc.Id + " - " ...
733
votes
14
answers
810k
views
What's the best way to determine the location of the current PowerShell script?
Whenever I need to reference a common module or script, I like to use paths relative to the current script file. That way, my script can always find other scripts in the library.
So, what is the best,...
684
votes
15
answers
651k
views
How to enter a multi-line command
Is it possible to split a PowerShell command line over multiple lines?
In Visual Basic I can use the underscore (_) to continue the command in the next line.
633
votes
1
answer
927k
views
How to handle command-line arguments in PowerShell
What is the "best" way to handle command-line arguments?
It seems like there are several answers on what the "best" way is and as a result I am stuck on how to handle something as simple as:
script....
625
votes
16
answers
946k
views
How can I check if a string is null or empty in PowerShell?
Is there a built-in IsNullOrEmpty-like function in order to check if a string is null or empty, in PowerShell?
I could not find it so far and if there is a built-in way, I do not want to write a ...
609
votes
8
answers
984k
views
How can I pass an argument to a PowerShell script?
There's a PowerShell script named itunesForward.ps1 that makes iTunes fast forward 30 seconds:
$iTunes = New-Object -ComObject iTunes.Application
if ($iTunes.playerstate -eq 1)
{
$iTunes....
588
votes
15
answers
923k
views
How do I pass multiple parameters into a function in PowerShell?
If I have a function which accepts more than one string parameter, the first parameter seems to get all the data assigned to it, and remaining parameters are passed in as empty.
A quick test script:
...
559
votes
11
answers
1.4m
views
Terminating a script in PowerShell
I've been looking for a way to terminate a PowerShell (PS1) script when an unrecoverable error occurs within a function. For example:
function foo() {
# Do stuff that causes an error
$host....
546
votes
13
answers
777k
views
Create directory if it does not exist
I am writing a PowerShell script to create several directories if they do not exist.
The filesystem looks similar to this
D:\
D:\TopDirec\SubDirec\Project1\Revision1\Reports\
D:\TopDirec\SubDirec\...