PowerShell is Microsoft's new scripting language in 2006, and significantly upgraded in 2009. It allows interpreted scripts based on PowerShell cmdlets and .NET primitives.

learn more… | top users | synonyms (1)

79
votes
8answers
70k views

How to zip/unzip files in Powershell?

Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
37
votes
22answers
14k views

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. ...
34
votes
7answers
29k views

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 ...
31
votes
8answers
46k views

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.
20
votes
2answers
858 views

Is there a way to loop thru Windows 8 Apps and remove them all

Windows apps are annoying and I would like to remove them. Been playing around with Powershell and scripting and I wanted to know if there was a way I could use powershell to loop all the apps and ...
19
votes
14answers
3k views

What are some good resources for learning PowerShell scripting? [closed]

Are there online resources or books that you would recommend as an introduction to PowerShell scripting? The resources I've found primarily focus on interactive use.
19
votes
8answers
2k views

PowerShell Quickstart [closed]

What is the best way you jump-started your Powershell adoption? What resources, tips, scenarios got you up to speed quickly?
18
votes
3answers
421 views

How do I delete this orphaned Active Directory computer object (preferably with PowerShell)?

I'm working from a Windows 7 workstation, with PowerShell v2.0, and trying to delete a particular (orphaned?) object from the LostAndFound container in a 2008 R2 FL forest and domain with the Active ...
16
votes
13answers
2k views

What's your favorite Powershell command or script for system administration? [closed]

What's your top Powershell command? Let's make a list and vote up the best ones!
16
votes
4answers
58k views

How to create Active Directory user account with powershell

I am constantly setting up research and development environments that require active directory accounts. Since we place these environments in isloated networks each environment needs its own active ...
16
votes
4answers
3k views

PowerShell Script to find AD users with adminCount > 0

I've recently discovered the "adminSDHolder" feature of Active Directory. I need a quick way to identify all users who will be affected by it, namely a script to dump the user accounts.
15
votes
3answers
1k views

Why does Powershell take so long to init?

When I fire up powershell it takes ~10-15 seconds to init and give me a prompt. Anyone know what it's doing when you first fire it up that might contribute to that? This is XP Pro, 2 GB of memory, ...
14
votes
4answers
21k views

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. ...
14
votes
8answers
5k views

Method to integrate Powershell scripts with non-Windows workflow?

I love the smell of new machines in the morning. I'm automating a machine creation workflow that involves several separate systems across my infrastructure, some of which involve 15 year old perl ...
13
votes
5answers
47k views

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 ...
13
votes
7answers
44k views

Powershell: How do I query pwdLastSet and have it make sense?

I need to get the last password change for a group of account in an Active Directory security group, and I feel like this is something PowerShell should be good at. Right now, I'm already stuck at ...
13
votes
4answers
20k views

How to set ExecutionPolicy: access to registry key denied

I'm running Windows Server 2008 as admin and I tried to set ExecutionPolicy as Remotesigned for PowerShell v2 like this: Set-ExecutionPolicy RemoteSigned But I got this error: Set-ExecutionPolicy ...
13
votes
2answers
1k views

Can Remote Desktop Services be deployed and administered by PowerShell alone, without a Domain in WIndows Server 2012 and 2012 R2?

Windows Server 2008 R2 allowed deployment of Terminal Server (Remote Desktop Services) without a domain, and without any insistence on domains. This was very useful, especially for standalone virtual ...
12
votes
4answers
12k views

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 ...
12
votes
6answers
24k views

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" ...
12
votes
2answers
273 views

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 ...
11
votes
4answers
20k views

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 ...
11
votes
2answers
7k views

In a PowerShell script, how can I check if I'm running with administrator privlieges?

In a PowerShell script, how can I check if I'm running with administrator privlieges?
11
votes
8answers
822 views

Expire Files In A Folder: Delete Files After x Days

I'm looking to make a "Drop Folder" in a windows shared drive that is accessible to everyone. I'd like files to be deleted automagically if they sit in the folder for more than X days. However, it ...
10
votes
3answers
13k views

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?
10
votes
1answer
238 views

How do I convert a vhd to a wim file?

I just setup and sysprepped a nice new VM, now I need to convert it to a wim real quick, to upload to my sccm server. For some reason, I can't change the VM properties to boot from a legacy nic for ...
9
votes
8answers
16k views

Easy way to rename all files in a directory in Windows [closed]

Is there an easy way to rename all the files in a directory? Is PowerShell the way to go? I'd like to go from this: c:\family_pics\ img123.jpg img124.jpg to this: c:\family_pics\ ...
9
votes
6answers
3k views

what are Powershell's advantages over cygwin/unix-shell

The obvious difference I'm aware of, is the ability to interface to certain MS products, such as Exchange. But for one not having to administer such products, what are the advantages of Powershell? ...
9
votes
5answers
1k views

Powershell - 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. Thanks EDIT: without the need of the activedirectory module!
9
votes
2answers
7k views

Best way to add HKCU keys and values for all existing users and all new users?

I need to add HKCU keys and values to all machines in a specific OU, for all existing user profiles and to the default profile. What's the best way to approach this? I could enumerate and iterate ...
9
votes
4answers
1k views

Powershell command to backup a SQL Server DB

Is there a PowerShell command that will execute a backup of all databases on a server? Alternatively, can I call a stored proc from PowerShell (that will execute the backup)?
9
votes
1answer
1k views

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 ...
9
votes
2answers
5k views

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 ...
9
votes
3answers
5k views

How to pass parameters to a function?

I need to process an SVN working copy in a PS script, but I have trouble passing arguments to functions. Here's what I have: function foo($arg1, $arg2) { echo $arg1 echo $arg2.FullName } echo ...
9
votes
1answer
679 views

What the heck is going on with this AD filter in PowerShell?

I recently wrote this answer and stumbled on something interesting. get-aduser -filter {-not (description -eq "auto")} | measure-object and get-aduser -filter {description -ne "auto"} | ...
8
votes
5answers
31k views

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?
8
votes
2answers
417 views

Detecting AD Site options using PowerShell

How can I use PowerShell to find AD site options like +IS_INTER_SITE_AUTO_TOPOLOGY_DISABLED in PowerShell? I've been playing around with the following command, but can't get it to spit out anything ...
8
votes
2answers
1k views

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

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 ...
8
votes
3answers
7k views

PowerShell remove force

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 ...
8
votes
6answers
568 views

Powershell challenge

I've been challenged by a friend to do the following: "Find the quickest and easiest way of sorting a directory listing by the LAST character of the filenames." He's done it on Linux using the ...
8
votes
4answers
6k views

What are Runspaces in Windows PowerShell 2.0?

Today I listened to a HanselMinutes podcast about PowerShell 2.0. Scott Hanselman interviewed Hal Rottenberg and Kirk Munro at TechEd 2009. They talked about RunSpaces in PowerShell 2.0. Can somebody ...
8
votes
1answer
188 views

Is there a version of the AD tools that provide the PowerShell output, similar to the Exchange tools?

The Exchange administration tools output the exact PS commands they will (or just did) execute. Is there a different version of the AD tools (primarily AD Users & Computers) that have similar ...
8
votes
4answers
649 views

PowerShell DSC copy from network share

I am trying to use PowerShell DSC to copy folder contents from a network share. Here is the code: Configuration TestSetup { Node localhost { File Test { SourcePath = ...
8
votes
1answer
1k views

Unzip File With Powershell in Server 2012 Core

I need to unzip a file with powershell. The typical way I've seen everyone do this is by automating the shell with a script. $shellApplication = new-object -com shell.application $zipPackage = ...
8
votes
2answers
70 views

Powershell Remotely Delete PKI Certificates

I recently rebuilt my PKI and I would like to delete the certificates that were issued to all client machines across my network. Sounds like a job for Powershell! So I wrote this script to be ...
8
votes
3answers
1k views

Windows Powershell Vim Keybindings

Is there a way to get vim keybindings in powershell as you would in bash or zsh with a command like set -o vi
8
votes
1answer
3k views

Remotely renaming a domained Win 7 computer

I'm having a hard time figuring out how to rename a Windows 7 computer remotely. This is for automating Win 7 builds in a vSphere 5 environment, and I'm trying to get it as hands-off as I can. So far ...
8
votes
1answer
229 views

How to accept EULAs for Software updates deployed through SCCM using Powershell

I'm trying to use the Start-CMSoftwareUpdateDeployment cmdlet to deploy a software update group to an existing collection. PS WHO:\> Start-CMSoftwareUpdateDeployment -SoftwareUpdateGroupName ...
8
votes
2answers
543 views

Using Diskpart in a PowerShell script won't allow script to reuse drive letter

I built a script that mounts (attach) a VHD using Diskpart, cleans out some system files and then unmounts (detach) it. It uses a foreach loop and is suppose to clean multiple VHD using the same ...
8
votes
4answers
9k views

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 ...