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
10
votes
3 answers

Using namespaces in Powershell

Thought about it while answering this question. How can you avoid the need to fully qualify every single type in a namespace? It's really, really tedious to write System.Security.Cryptography.X509Certificates.X509Store instead of X509Store, or…
Massimo
  • 70,200
  • 57
  • 200
  • 323
10
votes
3 answers

Stopping IIS websites permanently with PowerShell

Stopping websites using Stop-Website is, apparently, not the same as stopping them using the IIS Manager. Stop-Website 'Some site' iisreset.exe # site is started again Using IIS Manager, the state is the same after a reset/reboot. I guess stopping…
Bergius
  • 203
  • 2
  • 7
10
votes
2 answers

Get login name using email address with Powershell

I need a powershell script, to get login names using the e-mail address. i am having a note with e-mail address of some users. I want to get login IDs and account information of the users in the domain. Can any one help on this. Regards, Karthick.
10
votes
2 answers

Copy-item FileSystem provider error

Copy-item cmdlet is not working as expected, i don't understand why. This is my code : $Source = "C:\folder1" $Destination = "\\172.22.0.115\c$\folder2\" $Password = ConvertTo-SecureString -AsPlainText -Force -String "MyPassword" $User =…
10
votes
5 answers

How to find the creation date of a local user account?

I would like to get the creation date of a local user account (Win 7 if it matters). I've looked at the following WMI objects (and google of course): Win32_UserAccount Win32_NetworkLoginProfile The objects returned from NetworkLoginProfile have the…
MDMoore313
  • 5,581
  • 6
  • 36
  • 75
10
votes
4 answers

Editing/Setting Mime Types with Powershell?

So I was wondering if there is a specific way to change/edit a mime type in IIS 7.5 using powershell? So far I have come across solutions to add mimetypes such…
Orbital
  • 191
  • 1
  • 1
  • 8
10
votes
2 answers

Changing physical path on IIS through appcmd isn't activated

We have come across an issue on IIS 7.5 where we have a simple deploy system which consists of the following: Create a zip-file of new webroot, consisting of three folders: Api Site Manager This is unzipped into a new folder (let's say we call it…
jishi
  • 868
  • 2
  • 11
  • 25
10
votes
7 answers

Get filename in the case stored on disk?

I have a file README.TXT. If I issue the following command: PS> Get-Item ReadMe.txt ...then it returns "ReadMe.txt". I want to find out the actual name of the file on disk, including case. How do I get it to return "README.TXT"? I ask because I'm…
Roger Lipscombe
  • 2,177
  • 6
  • 24
  • 37
10
votes
2 answers

List ALL Printers using Powershell

I'm having issues listing all the printers on a computer using Powershell. We have a batch script that will add/remove/list "per computer" printers using PrintUI. I can use PrintUI to list the printers. rundll32 printui.dll,PrintUIEntry /ge…
Schlauge
  • 156
  • 1
  • 1
  • 6
10
votes
4 answers

How do I find orphaned computer objects in Active Directory using PowerShell?

How can I find all computer accounts in my Active Directory domain that have been inactive for x days using PowerShell? Note that I do actually know how to do this. This is a self-answered question just to get the knowledge out there. If anyone…
MDMarra
  • 100,734
  • 32
  • 197
  • 329
10
votes
11 answers

how to get MAC address of remote computer

I have specific situation. I want to get MAC address from a remote computer, which is not in domain. I know the hostname and IP address of the remote computer. The IP Address of my computer is 192.168.2.40 and the remote computer IP is…
culter
  • 507
  • 2
  • 9
  • 16
10
votes
2 answers

How do I grant permissions to remotely start/stop a service using Powershell?

We have a PowerShell script that restarts a service on another computer. When we use PowerShell's built-in service control cmdlets, like so: $svc = Get-Service -Name MyService -ComputerName myservicehostname Stop-Service -InputObject…
splattered bits
  • 928
  • 3
  • 11
  • 23
10
votes
2 answers

How can I set IIS Application Pool recycle times without resorting to the ugly syntax of Add-WebConfiguration?

I have been scripting the configuration of our IIS 7.5 instance and through bits and pieces of other peoples scripts I have come up with a syntax that I like: $WebAppPoolUserName = "domain\user" $WebAppPoolPassword = "password" $WebAppPoolNames =…
Chris Magnuson
  • 3,771
  • 10
  • 42
  • 46
9
votes
1 answer

Wrong password during pfx certificate import Windows(10, 2016)

I've tried to import a *.pfx certificate and I get an error about "Wrong Password". The error only appears on some systems. I've tested this on a few Windows 10 computers and on one Windows Server 2016. Windows 10 (did not work): build…
Iced
  • 111
  • 1
  • 1
  • 4
9
votes
2 answers

Powershell: Configure a static IP on an unplugged NIC

I'm trying to find a way to configure a permanent static IP on Windows 10 IOT devices with their Nic unplugged. I have a script that needs to be run on the devices before they're in place and part of it is configuring the NICs. When I use the…
Xelorz
  • 93
  • 1
  • 4