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)

16
votes
4answers
60k 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 ...
11
votes
1answer
2k 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 ...
82
votes
8answers
74k views

How to zip/unzip files in Powershell?

Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
10
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 ...
6
votes
11answers
24k views

Scripting - How to disconnect Remote Desktop sessions?

I am looking for a way to close all active Remote Desktop sessions on a computer (local computer). Windows includes a couple of commands (rwinsta, qwinsta, etc.) to look at the active sessions, but I ...
0
votes
1answer
2k views

Parse wevtutil XML into a database?

I'm by no means an XML expert. Ergo, I'm having trouble importing Windows event XML from wevtutil into an SQL database. Prior to Server 2008, we exported event log data to the database directly ...
4
votes
4answers
348 views

Is it possible to disable msiexec help GUI?

I'm automating unattended retrieval & installation of specified .msi packages with a powershell script but if the command is invoked with syntax errors the msiexec will wait indefinitely for an OK ...
4
votes
3answers
4k views

Enabling Powershell Remoting, Access is denied?

I am trying to enable Powershell remoting on a Windows 2008 R2 Server, running in workgroup mode. I ran the command Enable-PSRemoting in the PowerShell Console. PS C:\Windows\system32> ...
1
vote
1answer
1k views

replacing a line or date in a text file using powershell

I am trying insert today's date on a text file at line 59. How do i do this? Line 59 has like 30 spaces and then reads like this. After the PowerShell script runs it will change the date so it has to ...
0
votes
1answer
155 views

PowerShell Script to Move ADUser to appropriate group based on its Department ID attribute

I am new to PowerShell and AD, I have a small task which I am finding difficult to complete. Can someone please help me here ? The task is as follows: There are 3 groups defined in AD, namely ...
0
votes
1answer
145 views

Auto-Tagging EC2 Instances in AWS (Windows Servers only)

I am looking for some guidance from the serverfault community. We are spinning up several new AWS instances (windows server 2008/2012) over the next few days. We have a naming convention in place for ...
-1
votes
2answers
246 views

Can I use Powershell to configure Local group policy settings in windows server 2008 r2

in Windows server 2008 r2 , for this manual process open run >gpedit.msc > computer configuration > windows templates > windows update > specify intranet microsoft update service location > ...
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. ...
13
votes
7answers
46k 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 ...
11
votes
8answers
2k 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 ...
35
votes
7answers
31k 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 ...
8
votes
1answer
286 views

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

Execute program on remote computer using PowerShell

How can I execute a program on a remote machine using powershell?
6
votes
1answer
529 views

Running PowerShell scripts as an Application in MDT 2013

Is there a way to make powershell scripts run under the applications list so that when you install from the MDT image you can select which scripts you want to run? I can run the scripts fine as ...
4
votes
2answers
921 views

NTFS formatted removable storage, safely remove / unmount via command line?

We've just setup some removable storage for a file server we run in one of our offices (only supporting less than 10 work stations), one of our backup solutions is a removable harddrive that will ...
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 ...
6
votes
2answers
4k views

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

Why does my PowerShell script hang when called in PSEXEC via a batch (.cmd) file?

I'm trying to remotely execute a PowerShell script using PSEXEC. The PowerShell script is called via a .cmd batch file. The reason we do this is to change the execution policy, run the powershell ...
3
votes
2answers
1k views

Remotely run a script invoking “Run As Administrator”

This is as close to the exact question that I have, but looks like he found another way that fits the needs so it has been marked as answered: I have a Powershell script running on server A that I ...
3
votes
2answers
518 views

Connecting to Exchange PowerShell from a Linux machine

We currently have a Python script that automates user creation tasks on our servers. This script provisions users in OpenLDAP and ActiveDirectory by using python-ldap. Now, I want to modify some ...
18
votes
3answers
1k 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 ...
7
votes
3answers
18k views

Adding a user to the local Administrator group using powershell

I would like to use powershell to add a spesific user to the local administrator group on a machine. I would be running the powershell script in the context of a user that has Administration rights ...
6
votes
3answers
5k views

Run remote powershell as administrator

Before I dive into the question, I have found several other questions that seem similar to mine, but they have not been able to solve my problem. Here are links to them: Remotely run a script ...
6
votes
2answers
5k views

Server 2012 Server Core powershell not installed

In server core, after a restart powershell was all of a sudden not installed, what do I do to reinstall it? I do not have remote administration set up yet so I cannot use that to re-install it. ...
5
votes
3answers
5k views

How to enable volume shadow copy using Powershell?

How to enable volume shadow copy on specific drive (D:, E:,...) and set up schedule using Powershell ? I just need some hints how to start.
5
votes
1answer
5k views

Looking to add the “Log On as a service” right to an account via the command line

I am looking to make a user from the command line with minimal rights to run a service. cmd.exe or powershell.exe are both options, but cmd.exe is preferable. So far I got this: net user /add ...
4
votes
5answers
2k views

Is there a way to get PowerShell 2's remoting features to work between Windows XP machines?

PowerShell 2.0 has some super-snazzy remoting features. However, I'm unclear if they can be made to work with / between Windows XP machines, or if you need Windows Vista or Windows 7. ...
3
votes
2answers
72 views

What do the contents of PowerShell's $PSVersionTable represent?

If I echo $PSVersionTable in PowerShell, I get what appears to be multiple bits of version information. The name's of the properties are CLRVersion BuildVersion PSVersion WSManStackVersion ...
2
votes
2answers
4k views

Using Powershell to bulk change the Home folder path of AD objects - %username"?

I have done a lot of searching on this, and still cannot find the answer. I have created a script which will bulk move all user objects in one OU to another OU. This works fine. Now I am trying to ...
2
votes
2answers
2k views

Powershell wait for compressing to finish

I have written a PowerShell script that zips the contents of a folder and sends it to a server for backup. The issue is that the copy process doesn't wait for the zip process to finish. I have tried ...
2
votes
1answer
686 views

Using PowerShell to create user accounts from a CSV

How can I create a domain user account and set the default password in PowerShell from a CSV? Note that I know how to do this, I'm writing this as a self-answered question to share this knowledge. ...
2
votes
2answers
2k views

Listing Users using RDP

Windows Server 2008 R2 I'm trying to use PowerShell to get me a list of users who have logged into Remote Desktop Services (formerly known as Terminal Services) during the past day. With little ...
2
votes
3answers
715 views

Programmatically remove MSFT Security Essentials Anti-Virus from XP and Win7 machines

I need a way to remove MSFT Security Essentials so that I can install Forefront on the clients. I would prefer a login script that would pass administrator credentials to remove the program. If ...
1
vote
1answer
3k views

Error when adding bulk users in AD with PowerShell script

I'm trying to add users to AD using a PowerShell script that pulls info from a csv file. I've got it mostly working, in that users are created and they seem to work. However, I'm getting some ...
1
vote
3answers
2k views

Check existance of domain accounts with Powershell script

Is there a Powershell cmdlet or script to query Active Directory if a given domain account (such as "myDomain\myUser") exists?
0
votes
3answers
546 views

How can I install Powershell on Microsoft Hyper-V Server 2008?

I am running the stand-alone version of Hyper-V, Microsoft Hyper-V Server 2008, and would like to install Powershell. Ill be using it to use the Management Library script. How can I do this? Thanks, ...
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 = ...
7
votes
3answers
655 views

Delete a windows group in Active Directory

I am doing a cleanup of some AD groups that are no longer used. One of the AD groups I could not delete because it seems that a member has this group set as the primary group (which I assume someone ...
5
votes
1answer
260 views

identify / fingerprint a Windows Server core installation versus full

Seems like this should be easy, but I am not finding any information on how to remotely identify a Windows Server "core" installation as such, via WMI, Powershell or other method that can query lots ...
4
votes
1answer
861 views

Exchange 2010 Auto-mapping mailboxes feature doesn't work when groups grant permissions

I have a shared mailbox that I need to deploy to one of our departments in an Exchange 2010 SP2 environment with Outlook 2010 clients. I'm trying to rely on the auto-mapping feature introduced by ...
4
votes
1answer
3k views

Redirect stderr to variable in powershell

I would like to script a dcdiag test to alert me if it finds any errors. I thought I may able to do this in powershell by... $test = dcdiag 2>$err I don't have any errors from dcdiag at the ...
3
votes
2answers
403 views

Automatically reconfigure WinRM HTTPS listener with new certificate?

I am looking to enable WinRM HTTPS listeners on all of our servers for secure communication when using CredSSP between servers to get around the double-hop issue. Setting this up is fine, we have ...
3
votes
1answer
4k views

PowerShell Script to Loop Over All Users in a Group

I'm running Windows 7 Professional. I know how to get a list of all the users in a group: $ou="User Groups" $userADName="RRAS VPN SSL" ...
2
votes
1answer
271 views

Powershell enters foreach loop with null object

I'm listing all backups in a given directory: $backups = Get-ChildItem -Path $zipFilepath | Where-Object {($_.lastwritetime -lt (Get-Date).addDays(-7)) -and (-not $_.PSIsContainer) -and ($_.Name ...
2
votes
2answers
207 views

OutVariable is broken for Exchange 2010 cmdlets

It seems that OutVariable is broken when using the Exchange 2010 cmdlets. Is it just my server or is this the case for everyone? I observed the following -- get-mailbox jdoe -OutVariable asdf | ...