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.

4084 questions
163
votes
11 answers

How do I diff two text files in Windows Powershell?

I have two text files and want to find the differences between them using Windows Powershell. Is there something similar to the Unix diff tool available? Or is there another other way I haven't considered? I've tried compare-object, but got this…
Brian Willis
  • 3,619
  • 4
  • 21
  • 14
155
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…
Nathan Ridley
  • 2,599
  • 3
  • 19
  • 18
131
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?
Michael Kelley
  • 1,425
  • 2
  • 11
  • 9
104
votes
11 answers

How to zip/unzip files in Powershell?

Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
BlueGene
  • 2,241
  • 9
  • 30
  • 33
89
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,605
  • 2
  • 15
  • 11
62
votes
7 answers

Windows command prompt: how do I get the output of a command into a environment variable?

I want to have an environment variable that contains the day of week in cmd.exe. When I run this command I get the result I want. C:\Users\tisc> powershell (get-date).dayofweek Friday Here I'm trying to store the result in an environment…
Tim
  • 721
  • 1
  • 5
  • 8
61
votes
2 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,268
  • 5
  • 30
  • 40
59
votes
5 answers

How to search Powershell command history from previous sessions

I use current Windows 10 with Powershell 5.1. Often, I want to look up commands I have used in the past to modify and/or re-run them. Inevitably, the commands I'm looking for were run in a previous or different PowerShell window/session. When I…
shawmanz32na
  • 733
  • 1
  • 7
  • 6
59
votes
2 answers

Should I use semicolons at the end of each PowerShell statement?

I've done a fair bit of programming in C#, but then I've also written a lot of T-SQL scripts. C# requires semicolons, and T-SQL and PowerShell they're optional. What do you do for PowerShell? Why? My gut feel is to include semicolons but I don't…
Mark Allison
  • 2,188
  • 7
  • 26
  • 45
56
votes
4 answers

PowerShell script, showing commands run

I am playing around with PowerShell scripts and they're working great. However, I am wondering if there is any way to also show all the commands that were run, just as if you were manually typing them in yourself. This would be similar to "echo…
Nelson Rothermel
  • 573
  • 1
  • 5
  • 9
54
votes
5 answers

Need to add a "Wait" command to a Powershell script

Here is my current code: Write-output “ENTER THE FOLLOWING DETAILS - When Creating Multiple New Accounts Go to EMC hit F5(refresh) and make sure previous new account is listed before proceeding to the next one” $DName = Read-Host…
Paul Masek
  • 722
  • 2
  • 7
  • 16
54
votes
11 answers

SSH via PowerShell

Is it possible to open an SSH session in PowerShell? Currently I use PuTTY but it would be nice if that were not required.
nw.
  • 723
  • 2
  • 8
  • 12
46
votes
6 answers

Gaining administrator privileges in PowerShell

I only have one account on my Windows Vista machine, and that user has administrative privileges. However, when I try to execute a command within PowerShell to kill a certain process, I'm greeted with an "Access is denied" message. How do I become…
Brian
  • 737
  • 2
  • 9
  • 14
45
votes
22 answers

PowerShell? Do you use it? Can you show me some cool system administration things I can do with it?

I keep reading everywhere that PowerShell is the way of the future. When it was first released I did a whole bunch of virtual labs, but since then I still haven't used it in a production environment. I know the day will come when I'm dealing with…
42
votes
2 answers

Run Elevated Powershell prompt from command-line

Is there a way to run a Powershell Prompt with Elevated privileges from a command linein Server 2012? Problem is this is 'Minimal Server Interface' mode without full server-gui installed so I can run powershell from only either the command prompt or…
NickC
  • 2,373
  • 13
  • 41
  • 55
1
2 3
99 100