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

learn more… | top users | synonyms (1)

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

PowerShell - Install-WindowsFeature (and family) missing on Windows 10?

We have some Powershell scripts used to set up various dev/test/prod environments and one of them installs and configures IIS. Unfortunately these scripts don't appear to be working under Windows 10 ...
10
votes
2answers
5k views

How do you manually set Powershell's OneGet repository source to Chocolatey?

The OneGet Powershell module should ship with the default repository being Chocolatey. This is shown in the documentation found here. However when I run Get-PackageSource it returns PSGallery and ...
10
votes
1answer
2k views

Set-RDSessionCollectionConfiguration Connection Broker connects to localhost

I am running the following command from a PowerShell console on a Windows 8 machine, trying to configure a Server 2012 R2 RDS Connection Broker: Import-Module RemoteDesktop Set-...
10
votes
1answer
220 views

Can I change the update descriptions in WSUS?

On each Microsoft patch day, I have a pretty large amount of new updates I want to approve to my clients. But instead of 'Approve all updates and continue', I gather information on each update at its ...
10
votes
2answers
4k views

Issues with patching servers remotely using winrm and Microsoft.Update.Session

I have a network with windows 2003, 2008 and 2008r2 servers. I have a powershell script that I wrote to patch a local machine using the "Microsoft.Update" com objects. (Similar to Windows Update ...
10
votes
0answers
1k views

Import Powershell AD Module during MDT Task Sequence

I have written this short powershell script to rename a computer as part of an MDT task sequence: Import-Module ActiveDirectory $AdminUsername = 'domain.com\administrator' $AdminPassword = 'password'...
9
votes
8answers
29k 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
7answers
29k views

How do I set an environmental variable from a powershell command?

I want to have a environment variable that contains the day of week in cmd.exe. When I run this command I get the result I want. C:\Users\tisc>powershell (get-date).dayofweek Friday Here I'm ...
9
votes
6answers
4k 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
3answers
10k views

How do I diff two folders in Windows Powershell?

I'm trying to find differences in the content of two folder structures using Windows Powershell. I have used the following method to ensure that the file names are the same, but this method does not ...
9
votes
2answers
2k 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 ...
9
votes
3answers
6k views

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') { ...
9
votes
4answers
2k 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
3answers
18k 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
2answers
5k views

How can I compare installed hotfixes between two Windows servers using PowerShell?

I need to compare the installed patches between a dev and production environment using PowerShell. How can I do this?
9
votes
2answers
2k views

SSL Certificate management with Powershell DSC

I have a third-party issued certificate that I need to ensure is running on all targets in a given domain. Is there a way to ensure this certificate is installed by way of DSC?
9
votes
1answer
715 views

Small issue with the Domain Name System (DNS) Server Cmdlets

I'm wondering if I need to clear some cache or something with the issue I'm having. I'm trying to remove A records from a DNS Zone and replacing them with a CName record that has the same host name. ...
9
votes
3answers
3k views

powershell how to remove broken symlink

PS C:\> cmd /c mklink /d testlink non-existent-dir symbolic link created for testlink <<===>> non-existent-dir PS C:\> rm .\testlink Remove-Item : C:\testlink is a NTFS junction ...
9
votes
2answers
1k 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 ...
9
votes
2answers
8k views

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" $...
9
votes
1answer
1k 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"} | measure-...
9
votes
3answers
8k 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 ...
9
votes
2answers
3k views

ESXcli command timeout at 30 minutes

I am working on a powercli script to loop through each datastore in our environment and reclaim space on the thin provisioned LUNs. All LUNs in the environment are Dell Equal Logic. vCenter ...
9
votes
0answers
555 views

How to persist credentials in a remote Powershell session?

I have an Azure File Share and would like to use this from my Azure VMs - after persisting the credentials on the VMs with cmdkey and mounting with net use. This was tested by running these commands ...
8
votes
3answers
81k views

List All Groups and Their Members with PowerShell on Win2008r2

I am new to powershell, but I've been reading manuals and practiced a little bit. My objective is to List all users in all Security Groups under specified path. I have found the way to do it: get-...
8
votes
11answers
30k 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 ...
8
votes
1answer
3k views

Is it possible to enable MSMQ from PowerShell on Windows 8?

Is it possible to enable MSMQ from PowerShell on Windows 8(.1)? If so, how does one do this?
8
votes
6answers
621 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
50k views

Exchange 2010 Powershell command to check if an email address exists in the system

I'm looking for an Exchange 2010 command that would do the following: Given an email address (fully-qualified with domain and all) check if the email address is associated to some mailbox or group ...
8
votes
3answers
10k views

Install .NET 4 via command line or PowerShell?

How do I install .NET 4 on Windows Server 2008 R2 from the command line or PowerShell? This post shows how to do it for .NET 3.5 using dism.exe and PowerShell. I am guessing that, since the .NET 4.0 ...
8
votes
3answers
6k views

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....
8
votes
1answer
8k 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 ...
8
votes
2answers
21k 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. '...
8
votes
1answer
289 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
3answers
753 views

PowerShell: Get-ADUser Properties with åäö

I'm trying to extract select sets of users with Get-ADUser. The users belong to companies whose names include non-ASCII characters, e.g. "Gåäördet". Unfortunately, we do have to use the company ...
8
votes
2answers
12k 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 ...
8
votes
3answers
7k views

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

PowerShell Remoting w/ Exchange 2010: Value cannot be null

I'm having difficulty running Exchange 2010 cmdlets through remote PowerShell sessions. I start my local PowerShell session as Administrator and issue the following commands -- PS C:\Windows\...
8
votes
2answers
320 views

Powershell's equivalent to Bash's process substitution

Bash has <(..) for process substitution. What is Powershell's equivalent? I know there is $(...), but it returns a string, while <(..) returns a file the outer command can read from, which is ...
8
votes
1answer
818 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
4answers
2k views

Test-Cluster Powershell cmdlet List vs Validate

The Powershell cmdlet Test-Cluster queries a myriad of data and performs validation tests which it wraps into a pretty report. If you run Test-Cluster -List you get a list of item's you can ...
8
votes
2answers
947 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
2answers
3k views

Is there a way to show an RDP session's encryption level from the commandline/Powershell?

For Windows 2008, I need to create a script that will show whether connected RDP sessions are set at "high" encryption or something else (e.g., "compatible"). Does anyone know of a way to get this ...
7
votes
3answers
33k views

Writing a powershell script to copy files with certain extension from one folder to another

I would like to write a powershell script that gets the following parameters as input: Folder to copy from, extensions allows, folder to copy to and a boolean indicating if the change should restart ...
7
votes
5answers
11k views

How to run a PowerShell script from Cygwin SSH session?

Hi I have Windows Server 2003 with CopSSH installed on it ( Cygwin + sshd ). W would like to be able to run a PowerShell script via SSH session command and then use it's output. Is there such ...
7
votes
6answers
12k 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.
7
votes
8answers
312 views

Is Vanilla Powershell Enough of a Language for Windows & DB Server Admins?

Does a clean install of PowerShell on its own have enough functionally to Admin a Windows domain environment and/or SQL Servers? If not what are good, free or pay for, third party add-ons?
7
votes
2answers
2k views

Automating WSUS via PowerShell

I have written a script with the intention of quickly managing the WSUS process, and I have a few things I hard coded in, but would rather get with PowerShell. In particular, the 'Target' groups for ...