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
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…
Mauricio Scheffer
  • 831
  • 2
  • 10
  • 23
38
votes
5 answers

Access network share without mapping drive letter (PowerShell)

I want to access a remote SMB network share \\SHARE-HOST\ without mapping a drive letter. I can manually do it in windows by typing \\SHARE-HOST\Share_folder\ in explorer. If I want to do it programatically I have to use the net use command. This…
ServerAdminGuy45
  • 401
  • 1
  • 4
  • 3
36
votes
3 answers

ssh on windows - Corrupted MAC on input

I've installed OpenSSH on Windows. I can successfully connect to my remote server via ssh with Putty from this Windows machine. But when opening a PowerShell, and trying ssh my_user@1.2.3.4 I've got the error: debug3: send packet: type 5 …
Raoul Debaze
  • 521
  • 1
  • 4
  • 6
36
votes
8 answers

How to get robocopy running in powershell?

I'm trying to use robocopy inside powershell to mirror some directories on my home machines. Here's my script: param ($configFile) $config = Import-Csv $configFile $what = "/COPYALL /B /SEC/ /MIR" $options = "/R:0 /W:0 /NFL /NDL" $logDir =…
Mark Allison
  • 2,188
  • 7
  • 26
  • 45
33
votes
4 answers

Check if user password input is valid in Powershell script

I am working with a Powershell script that adds scheduled tasks to systems in our domain. When I run this script, it will prompt me for my password. I sometimes fat finger the password and the process starts, which locks out my account. Is there a…
Doltknuckle
  • 1,254
  • 7
  • 25
  • 32
32
votes
5 answers

Managing Windows Powershell from Linux terminal

I manage Windows Server 2012 servers. I'm learning PowerShell to manage these servers through command line. My workstation runs Ubuntu and I usually manage Linux servers by connecting via SSH. Is there a way that I can use Windows PowerShell on…
Ederson
  • 575
  • 2
  • 8
  • 13
32
votes
4 answers

How do I run my PowerShell scripts in parallel without using Jobs?

If I have a script that I need to run against multiple computers, or with multiple different arguments, how can I execute it in parallel, without having to incur the overhead of spawning a new PSJob with Start-Job? As an example, I want to re-sync…
Mathias R. Jessen
  • 25,161
  • 4
  • 63
  • 95
31
votes
3 answers

PowerShell - Install-WindowsFeature (and family) missing on Windows 10?

We have some Powershell scripts used to set up various dev/test/prod environments and one of them installs and configures IIS. Unfortunately these scripts don't appear to be working under Windows 10 at this time because the Install-WindowsFeature…
Mr. Smythe
  • 643
  • 1
  • 8
  • 13
30
votes
10 answers

Retrieve current domain user's full name

Using PowerShell, how can I get the currently logged on domain user's full name (not only its username) without the need of the ActiveDirectory module?
Jonathan Rioux
  • 1,938
  • 6
  • 33
  • 57
30
votes
6 answers

How to properly add .NET assemblies to Powershell session?

I have a .NET assembly (a dll) which is an API to backup software we use here. It contains some properties and methods I would like to take advantage of in my Powershell script(s). However, I am running into a lot of issues with first loading the…
amandion
  • 323
  • 2
  • 4
  • 7
29
votes
1 answer

How do I add the Windows GUI to Windows 2016 Server Core?

We just got our dedicated server from Rackspace. It was loaded with W2008 on it. I decided to put the most recent OS on it so I wouldn't have to upgrade it later. Apparently during the installation, I selected the no gui option. I tried to install…
28
votes
6 answers

Recycle remote IIS app pool from the command line?

Is it possible to recycle an IIS7 app pool from the command line, on a different machine? I've found APPCMD (appcmd recycle apppool my-app-pool), but it only operates on the host it's run on, AFAICT. I heard a rumor there might be a way to do it…
Ken
28
votes
8 answers

How to use a config file (ini, conf,...) with a PowerShell Script?

Is it possible to use a configuration file with a PowerShell script? For example, the configuration file: #links link1=http://www.google.com link2=http://www.apple.com link3=http://www.microsoft.com And then call this information in the PS1…
Xavier C
  • 733
  • 2
  • 9
  • 12
28
votes
13 answers

Windows command prompt: how to get the count of all files in current directory?

What command would you use in cmd.exe to find the number of files in the current directory? Is there a powershell option here? Update: I was hoping to avoid dir, as I know there are 10,000+ files in the current directory. Wanted to avoid the…
27
votes
6 answers

Change the Powershell $profile directory

I would like to know how to change my the location my $profile variable points to. PS H:\> $profile H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 H:\ is a network share, so when I create my profile file, and load powershell I get the…
Swoogan
  • 2,087
  • 1
  • 14
  • 21