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)

7
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
7
votes
2answers
3k 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 ...
7
votes
3answers
7k 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 ...
6
votes
1answer
432 views

Why does ForEach behave differently than % even though they are both aliases of ForEach-Object in Powershell?

For some reason the % alias for ForEach-Object throws an exception when using the ( $Thing in $Things) syntax while the ForEach alias works fine. Here are two examples: Using the % alias: $ints = ...
6
votes
7answers
29k views

How do I turn windows features on or off using powershell or commandline in windows 7?

I have scripted against sysocmgr in windows xp, servermanagercmd in server 2008, and now I find that I have to use a new powershell module servermanager to install features on Server 2008 R2 and so I ...
6
votes
2answers
1k views

Where do you share or find useful powershell, bash, batch, vbs, scripts?

I just wrote a quick little powershell script to make my life easier for a task that I was facing. I thought it would be nice to put it on the Internet, where someone else may also find it useful. The ...
6
votes
3answers
569 views

How to get a user's privileges?

I can get the logged in user's privileges in powershell like so: whoami /priv How do I do this for a user I'm not logged in as?
6
votes
3answers
16k 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
4answers
4k views

Query schtasks using Powershell

On a Windows7 machine I am trying I can run a query to view all the scheduled tasks using schtasks.exe This is fine but I would also like to filter the result set using something like schtasks ...
6
votes
1answer
1k 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?
6
votes
2answers
3k 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. ...
6
votes
2answers
3k 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 ...
6
votes
2answers
1k views

Test for Localhost in Powershell?

I have a powershell script that calls Get-WmiObject with -Credential. However, this errors out if I am running it against the local machine: Get-WmiObject : User credentials cannot be used for local ...
6
votes
2answers
90 views

Managing multiple PowerShell prompts

If I have multiple Powershell Prompts to different machines, it can get confusing. While, the command prompts all show the machine I am at, I was trying to find a solution that changed the titlebar ...
6
votes
2answers
386 views

powershell: How to check if S.M.A.R.T is enabled on remote machines

I was attempting to get disk info of remote machines, including whether or not SMART is enabled on the drive by using the win32_diskdrive class. This is trickier than I thought. While it's easy ...
6
votes
3answers
3k views

Find files across all drives using Powershell

I know how to search for files using dir/gci, but that only works across one drive AFAIK. Is there a way to search across all drives on the computer? Is there a way without manually enumerating then ...
6
votes
1answer
1k views

PowerShell 3.0 x64 bit broken after installing KB2506143

I have searched using all kinds of variations on relevant terms and I cannot find a single other instance of someone else having this excact same problem, so I am hoping someone here may have a clue. ...
6
votes
3answers
3k 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
6answers
2k 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 ...
5
votes
11answers
49k views

Windows command prompt: how to get the count of all files in current directory?

What command would you use in cmd.exe to find the number of files in the current directory? Is there a powershell option here? Update: I was hoping to avoid dir, as I know there are 10,000+ files in ...
5
votes
11answers
22k 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 ...
5
votes
2answers
4k 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 ...
5
votes
4answers
14k views

Creating a Share with Permissions with Windows Powershell

Using Powershell how can I create a share and set access permissions. For example as follows Create share called "public" that maps to the "path c:\shares\foo" Allow DOMAIN1\Users to have ...
5
votes
4answers
5k views

How can I run a PowerShell function remotely?

Using powershell, I plan to run many functions on a remote host to gather information. Here is an example to retrieve the content of file remotely just by running a function called getcontentfile ...
5
votes
1answer
217 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 ...
5
votes
5answers
1k views

VMware ESX Auditing

I'm looking to generate an excel spreadsheet with various information about each one of my company's ~140 VMs residing on 7 ESX 3.5 servers - specifically, the VM's: Name Allocated Memory, ...
5
votes
2answers
769 views

Powershell 2: Optimal way to compute checksum on file?

I run a script to process a CSV file once an hour. At the beginning of the script, I need to exit out if the CSV file has not changed. Let's pretend that file timestamps aren't an option. (I'm asking ...
5
votes
3answers
3k views

Stripping lines from text file with Powershell

I am trying to remove specific lines from a text file. The text file is just a list and I want to remove specific entries if they are present. So what I have is this: $f=${path_to_file} for($i = 0; ...
5
votes
2answers
2k views

How can I use powershell scripting to change SQL Server Aliases?

I have an x64 machine that regularly needs about 10 aliases changed in the SQL Server Client Network Utility (cliconfig) for both the x64 and x86 sides of the registry. Is there a way I could do this ...
5
votes
2answers
202 views

Erroneous Tasklist.exe

I’m currently managing a Citrix-farm system based on Windows Server 2008R2. In the past, I had used a Powershell script to check for running user-processes and restart them if necessary. I used the ...
5
votes
1answer
453 views

How can I get the “description” attribute of an OU in ActiveDirectory?

I'm working on a set of script that will be used to migrate the users and structure from one active directory to another. For this, I'm using the Get-ADOrganizationalUnit commandlet to export the OUs ...
5
votes
3answers
3k 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') { ...
5
votes
1answer
1k views

Sudo !! equivalent in PowerShell

"Sudo !!" invokes previously executed command with administrator privileges in *nix shell. Is there an equivalent in PowerShell?
5
votes
1answer
470 views

Script to remove Exchange 2010 AutoMapping for all mailboxes

I have an Exchange 2010 SP3 server that's getting Application event error 9646 from MSExchangeIS: Mapi session [ID] [AD User] exceeded the maximum of 500 objects of type "objtFolder" Looking into ...
5
votes
1answer
282 views

How to override the default dir alias in Powershell?

I wanted to see colorized filenames when I typed dir in Powershell. So, I added the Set-ChildItemColor function from here to my profile file. I also added this line at the end of the profile file to ...
5
votes
2answers
1k views

How to pin powershell scripts to taskbar? [closed]

I'm using windows server 2008 R2 and it wont allow me to pin powershell scripts to the taskbar. Anyone know why and how I can pin powershell
5
votes
3answers
2k 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 ...
5
votes
9answers
2k views

What scripting language do you use for your logon scripts in your Windows enviroment?

I wonder what scripting languages is most used as logon scripts these days. Is people still hacking away in batch-file files or vbscripts, or do you use PowerShell or something completely different? ...
5
votes
2answers
64 views

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

DIRing folders in PowerShell

Now that in Powershell dir is just an alias to Get-ChildItem, how can I get a list of just folders? I've been doing dir /ad (for Attribute Directory) in the command prompt for about 20 years. Is ...
5
votes
3answers
2k views

Powershell: Execute exe on remote server and capture output

I am trying to script the execution of an installer on remote web servers. The installer in question is also a Windows Service that hosts NServiceBus. If RDP'd into the server, the application is ...
5
votes
2answers
526 views

Exchange 2010 Powershell commands?

I was wondering if anyone knows the PowerShell command for Exchange 2010 that lists mailboxes and/or users that a particular mailbox does NOT have access to. We have a system account that we need to ...
5
votes
1answer
8k views

How to ignore an error in Powershell and let it continue?

I am trying to see if a process is running on multiple servers and then format it into a table. get-process -ComputerName server1,server2,server3 -name explorer | Select-Object ...
5
votes
1answer
56 views

DSC, how to know if after running the configuration a reboot is required

So I'm using DSC Push mode I have about 200 deployments per day to several environments (DEV/INT/QA/PROD) Every time that I deploy I want to make sure that each server is configured correctly So ...
5
votes
1answer
168 views

Checking partition alignment with PowerCLI

I'm trying to verify that the file system partitions within each of the servers I'm working on are aligned correctly. I've got the following script that when I've tried running will either claim that ...
5
votes
1answer
260 views

How can I list hidden administrative shares using PowerShell?

I'm trying to write a script that will audit shared folders on a few HIPAA-sensitive servers. I'm getting a list of shares just fine using gwmi Win32_Share, however when I go to get the permissions on ...
5
votes
1answer
221 views

How can I change the IIS default document order using Powershell?

How can I make sure default.aspx is the first default document for my IIS website? I have tried: Add-WebConfiguration //defaultDocument/files "IIS:\sites\Default Web Site\MyWebSite" -atIndex 0 ...
5
votes
1answer
596 views

Powershell Registry value to be used as variable

I am looking on how to return one value from the registry. I only want the AGENTGUID value from this command. $reg=reg query "\\$computer\HKLM\SOFTWARE\Wow6432Node\Network Associates\ePolicy ...
5
votes
2answers
2k views

Installing an SSL Certificate in Windows Server 2008 using powershell

Is it possible to Install an SSL Certificate in Windows Server 2008 R2 using powershell? If it's not, is it possible with cmd command line? I am doing it with mmc now but would it be nice to do that ...
5
votes
1answer
201 views

Why is $pshome in a “v1.0” directory?

I'm clearly running powershell v2.0.x on Windows 7. PS C:\> $PSVersionTable Name Value ---- ----- CLRVersion 2.0.50727.5444 ...