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
2
votes
1 answer

Powershell to add users to a group

I have written this bit of PS to add users from a text file to and AD group that the user inputs. It works fine except for the if statement. The if statement is supposed to check the group to see if the users in the text file are already group…
user179037
  • 77
  • 1
  • 3
  • 7
2
votes
1 answer

MSSQL Server 2012 Scheduled PowerShell Job fails

I have a simple PowerShell script that runs fine from the console (PSVersion 2.0). $psftpPath = "C:\Program Files (x86)\PuTTY\psftp.exe" $sftpHost = "foo.baa.com" $userName = "myusername" $userPassword = "mypassword" $todate = Get-Date -format…
Colin
  • 121
  • 2
2
votes
1 answer

What can cause Powershell execution policy not to be taken into account?

We have in our infrastructure a number of powershell scripts used for various tasks ranging from user login to support technician simulating a user context. These scripts are centralized on our file server (through DFS) for easier management. Some…
Stephane
  • 6,432
  • 3
  • 26
  • 47
2
votes
1 answer

PowerShell Command 'write-zip' doesn't work

I am using a Powershell script to compress some files into a .zip file. My entire script looks like this: Write-Host "Creating Zip File... " -NoNewLine write-zip ("file1.txt", "file2.txt", "file3.txt", "logs") log.zip Write-Host "Done" This script…
user26712
  • 329
  • 1
  • 4
  • 10
2
votes
2 answers

Powershell Script to Zip Files

I'm new to Powershell. I have a need that I assumed that it would be perfect for. However, I've quickly come to the point where I feel I'm in over my head. Basically, I need to create a .zip file. I have a directory that looks like the…
user26712
  • 329
  • 1
  • 4
  • 10
2
votes
1 answer

Powershell - Get Disk IO performance counter

I am very new to Powershell. I need to get Page Faults and Disk IO of system while a particular process is running. I am able to get Page Faults but not able to get Disk IO. Can u guys help me please. Below is my code: $arrayDIO = @() $arrayPf =…
Avadhani Y
  • 123
  • 1
  • 1
  • 6
2
votes
1 answer

Get PowerShell warning about scripts back

I've found several questions about how to suppress warnings like this: Security Warning Run only scripts that you trust. While scripts from the Internet can be useful, this script can potentially harm your computer. Do you want to run…
jpmc26
  • 141
  • 1
  • 8
2
votes
6 answers

Server 2012 GPO: PowerShell Script on Computer Startup not running

I've got a couple of Server 2012 instances on Amazon EC2 and I'm in the process of setting up the GPOs. All of the settings of the GPOs are being applied fine, except none of the PowerShell scripts specified on computer startup are actually being…
Gup3rSuR4c
  • 661
  • 3
  • 14
  • 29
2
votes
1 answer

How can I unload multiple registry hives in PowerShell? (Access Denied error)

I've loaded dozens of registry hives as HKLM:\temp_$username\. Now when I try to run ls HKLM:\temp_* | %{reg unload $_} I get ERROR: Access is denied. I'm running PowerShell with elevated priveleges and tried restarting PowerShell ISE to clear out…
rtf
  • 884
  • 2
  • 17
  • 31
2
votes
1 answer

Windows 2012 & Remote Desktop Users group

On Windows Server 2012, it seems that, by default, only users in the Administrators group are permitted to log on remotely to a Windows 2012 server. How can I use PowerShell to allow users who are in the "Remote Desktop Users" group (but not in the…
Lorin Hochstein
  • 5,028
  • 15
  • 56
  • 72
2
votes
4 answers

Start-BitsTransfer Works when triggered manually from powershell but not using a windows service

I'm using BITS to transfer file from one windows 2008 R2 server to the other. When I run the command manually from powershell or regular command line it works perfectly. Now when I use the same command as part of a build script in Jenkins it fails…
newbie
  • 763
  • 1
  • 10
  • 12
2
votes
2 answers

How can I move Exchange items to a PST using PowerShell?

We have a mailbox that receives status emails that we need to keep essentially for ever, and they contain potentially large attachments. I need to be able to move these messages to a PST on a regular (daily or weekly) basis so want to automate…
Cylindric
  • 1,127
  • 5
  • 24
  • 45
2
votes
2 answers

How to include "Host Component" of HyperV in backup with wbadmin?

I'm trying to set up a script to run the backups of my Virtual Machines only using WBADMIN, I've got as fas as being able to backup all the VMs using the new -HyperV switch, however I also want to backup the HyperV Host Component. Does anyone have…
Harrison
  • 63
  • 1
  • 7
2
votes
2 answers

How can I reset settings for Internet Explorer using a script?

I'm looking to reset Internet Explorer back to factory defaults using a batch file. I'd also like to delete: all Downloads, History, Cookies and Cache, plus anything else in a user's IE profile.
Emad Alzaobi
  • 31
  • 1
  • 1
  • 2
2
votes
1 answer

Remote disk monitoring with WMI without admin rights

I am setting up a restricted WMI group that should be able to read WMI information from my remote hosts. I have the group set up as member of the remote DCOM and performance monitor groups. I also have the Execute, Enable and Remote Enable set in…
Tim Brigham
  • 15,545
  • 10
  • 75
  • 115