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
14
votes
5 answers

Powershell Switch statement with multiple values

Anyone know how I can have a switch statement with multiple possible values like the example below? switch ($myNumber) { 1 3 5 7 9 { write-host "Odd" } 2 4 6 8 10 {write-host "Even" } } Used to be easy in VBScript, so I'm sure i'm just…
Ben
  • 1,137
  • 9
  • 26
  • 44
13
votes
1 answer

Configure Hyper-V VM powershell

How can i reconfigure Hyper-V VM's I want to be able to change the VM configuration file, check points, and virtual hard drive locations with Powershell. My Google-FU is only pointing me at moving, I have about ~100 VM's to Change, I can move the…
Anthony Fornito
  • 9,546
  • 1
  • 34
  • 124
13
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
  • 133
  • 1
  • 1
  • 5
13
votes
6 answers

Cannot set Powershell ExecutionPolicy for CurrentUser

Here is a sample of the commands I am running: PS C:\> Get-ExecutionPolicy -List Scope ExecutionPolicy ----- --------------- MachinePolicy Undefined UserPolicy Undefined Process Undefined CurrentUser …
Camron B
  • 311
  • 1
  • 2
  • 9
13
votes
1 answer

Using icacls to list ownership of directories

I am trying to find out is IIS_IUSRS has FullControl of certain folders under directories. Example I have c:\inetpub\sites\ Under c:\inetpub\sites\ i have about 50 site folders In each folder i have 3 folders called uploads, media, requests. I would…
Anthony Fornito
  • 9,546
  • 1
  • 34
  • 124
13
votes
2 answers

New-ADUser -Name Length too long

I need to add about 500 users to an OU in AD I have scripted out everything I need, however, it gives the error: the name provided is not a properly formed Here is the script New-ADUser -Name C080CAB1-9756-409F-914D-AE3971F67DE7 -Path…
Anthony Fornito
  • 9,546
  • 1
  • 34
  • 124
13
votes
2 answers

What is the industry standard method for administering the change of the local administrator password for all machines on a domain?

Although there appears to be three available options, one of which is actually secure, there seems to be only two available choices that will be able to impact machines that are not powered on at the time of change or are mobile and were not on the…
13
votes
3 answers

Is ServerManager module available on Windows 7?

Is ServerManager module available on Windows 7 Ultimate ? I think (but I'm not sure because I never looked at output before) the PS script that I have worked before but after some problems with IIS7 installation it stopped working. Following…
expert
  • 322
  • 1
  • 3
  • 14
13
votes
5 answers

How can I add ACL permissions for IIS APPPOOL\* accounts via Powershell?

I want to be able to set the IIS account for new websites to have modify permissions. I have the following script: function Set-ModifyPermission ($directory, $username, $domain = 'IIS APPPOOL') { $inherit =…
bdukes
  • 235
  • 1
  • 2
  • 9
13
votes
7 answers

How to determine 32 or 64 bit version of Windows Server 2008 using Powershell?

Using the Powershell console, what command/commands can be executed to determine if the 32 or 64 bit bersion of Windows Server 2008 is installed?
Matt Spradley
  • 344
  • 1
  • 5
  • 12
12
votes
1 answer

Sync Two IIS 8.5 Server configurations only excluding bindings

We have two IIS 8.5 web servers, Server 2012 R2 Server1 Server2 I am trying to find a powershell command that will sync only changes made on Server1 to Server2 I tried shared configurations however that will sync the bindings as well and I do not…
Anthony Fornito
  • 9,546
  • 1
  • 34
  • 124
12
votes
7 answers

How do I completely turn off Windows Defender from PowerShell?

Set-MpPreference -DisableRealtimeMonitoring disables the first one, what are the specific switches to disable the others you see when you open the UI? I have not found a clear example of this in the docs and I don't feel like running EVERY disable…
red888
  • 4,183
  • 18
  • 64
  • 111
12
votes
1 answer

How to use powershell to administer Hyper-v Cluser

I have 2 hosts both with Server 2016 Datacenter On each host I have 2 VM's currently Dev using shared storage I can do all the cluster things ie., Live migrate, move storage, I have been looking all over google for a script to be able to save all…
Anthony Fornito
  • 9,546
  • 1
  • 34
  • 124
12
votes
1 answer

Scheduled restart of a service with powerhshell as non-admin service account

Before I get shot down, I know how to schedule a task, restart a service with powershell or give a non-admin account the privileges to restart a service. That isn't the problem. The problem however is the combination of all these three tasks…
12
votes
1 answer

why is it wrong to call functions with parentheses in Powershell?

This question is a spin-off to a comment in another question Powershell fails to retrieve pwdLastSet from Active Directory This is where I tried calling the function like this: Get-PwdLastSet('grz') I received the following hint which I truly…
GrzegorzOledzki
  • 998
  • 6
  • 21