Questions tagged [powershell]

An interactive shell, scripting and programming language, and surrounding environment from Microsoft. Commonly used by system administrators managing Microsoft software (including Windows, Exchange, SharePoint, and cloud services Azure and Office 365), PowerShell is included by default with Windows, and takes over from previous languages such as VB Script.

PowerShell exists to create a more powerful shell than Command Prompt, a more capable language than VBScript, and an environment with built-in support for remote servers and code documentation. Since its introduction, Microsoft added support for PowerShell scripting to many of their core products.

This comment by Jeffrey Snover, one of the original designers of PowerShell, explains the ideas and intent behind the language, and why it was developed instead of porting something like Bash from a Unix environment.

PowerShell provides a vastly improved scripting environment for Windows compared to previous .bat and .vbs methods; it includes PowerShell ISE - an editor and debugging environment, on the language side it has easy support for using lists, hashtables and regular expressions for pattern matching, as an interactive shell it has tab completion for command parameters and interactive help via Get-Help, and it can natively work with COM objects, WMI, registry values, call out to any .Net Framework method or library, and create and use modules written in PowerShell code.

Microsoft Software that supports PowerShell for management includes: Windows Server (and many roles and features - Active Directory, IIS, DNS Server), Exchange Server, SQL Server, SharePoint Server, Windows Azure, and Office 365 components. Here is a full list of PowerShell modules included in Windows Server 2012 and Windows 8.1.

First released in 2006 as a downloadable addition to Windows XP and Server 2003, PowerShell has been significantly upgraded in 2009 (v2) with the addition of remote execution of scripts, and in 2012 (v3), 2014 (v4), and 2016 (v5). In 2018 Microsoft released PowerShell Core (v6) which was open sourced and runs cross-platform on Windows, Mac, and Linux.

4128 questions
158
votes
2 answers

Sometimes PowerShell stops sending output until I press enter. Why?

Periodically I notice PowerShell seems to take forever to finish doing whatever it is I told it to do until it occurs to me to "wake it up" by pressing enter. This is not the fault of any one process as best I can tell, as I have even run custom…
144
votes
7 answers

In a PowerShell script, how can I check if I'm running with administrator privileges?

In a PowerShell script, how can I check if I'm running with administrator privileges?
91
votes
4 answers

What is the literal escape character in Powershell?

When including a literal quote character inside a quoted string in Powershell, how do I escape the quote character to indicate it is a literal instead of a string delimeter?
David Alpert
  • 1,625
64
votes
3 answers

How to ignore an error in Powershell and let it continue?

I am trying to see if a process is running on multiple servers and then format it into a table. get-process -ComputerName server1,server2,server3 -name explorer | Select-Object processname,machinename Thats the easy part - When the process does not…
Jake
  • 2,318
42
votes
11 answers

Force-remove files and directories in PowerShell fails sometimes, but not always

I am trying to delete a directory recursively with rm -Force -Recurse somedirectory, I get several "The directory is not empty" errors. If I retry the same command, it succeeds. Example: PS I:\Documents and Settings\m\My Documents\prg\net> rm -Force…
22
votes
3 answers

Add a binding to an IIS site using powershell

I'm trying to control bindings in an IIS app using powershell. I'd like to create a site with both a http and https binding using a script. This is what I have thus far: Param( [Parameter(Mandatory=$True,Position=1)] [string]$hostname, …
Khanzor
  • 331
20
votes
4 answers

Why does Powershell take so long to init?

When I fire up powershell it takes ~10-15 seconds to init and give me a prompt. Anyone know what it's doing when you first fire it up that might contribute to that? This is XP Pro, 2 GB of memory, only Outlook and Firefox running interactively,…
squillman
  • 38,013
20
votes
1 answer

Redirect standard error to a variable in PowerShell

I would like to script a dcdiag test to alert me if it finds any errors. I thought I may able to do this in PowerShell by... $test = dcdiag 2>$err I don't have any errors from dcdiag at the moment, so I couldn't test that directly, but I wrote…
Matt
  • 1,142
20
votes
8 answers

PowerShell Quickstart

What is the best way you jump-started your Powershell adoption? What resources, tips, scenarios got you up to speed quickly?
18
votes
2 answers

Powershell's equivalent to Bash's process substitution

Bash has <(..) for process substitution. What is Powershell's equivalent? I know there is $(...), but it returns a string, while <(..) returns a file the outer command can read from, which is what it expects. I'm also not looking for a pipe based…
IttayD
  • 1,107
18
votes
2 answers

How do you manually set PowerShell's OneGet repository source to Chocolatey?

The OneGet PowerShell module should ship with the default repository being Chocolatey. This is shown in the documentation found here. However when I run Get-PackageSource it returns PSGallery and MSPSGallery as the sources. How can I manually set…
18
votes
5 answers

Powershell delete files only from directory

I'm trying to delete all files (but not directories) in D:\MyTemp folder, I've tried: Remove-Item "D:\MyTemp" Remove-Item "D:\MyTemp\*" However, when I check, all the files are still there. What am I missing?
SteB
  • 1,009
  • 6
  • 16
  • 31
17
votes
5 answers

Writing a powershell script to copy files with certain extension from one folder to another

I would like to write a powershell script that gets the following parameters as input: Folder to copy from, extensions allows, folder to copy to and a boolean indicating if the change should restart IIS, username and password. What cmdlets should I…
the_drow
  • 322
  • 2
  • 4
  • 11
16
votes
13 answers

What's your favorite Powershell command or script for system administration?

What's your top Powershell command? Let's make a list and vote up the best ones!
Jon Galloway
  • 1,506
  • 1
  • 18
  • 20
15
votes
1 answer

PowerShell pipe into find.exe command

Just curious, why does this happen? If I run: netstat -an | find "443" into a command prompt, "443" connections are displayed ok. If I run the same command in a PowerShell console or ISE, I get the error "FIND: Parameter format not correct". Is…
Vic
  • 153
  • 1
  • 1
  • 5
1
2 3
29 30