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.

Filter by
Sorted by
Tagged with
174 votes
10 answers
301k 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 ...
Brian Willis's user avatar
  • 3,839
158 votes
2 answers
58k 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 ...
Nathan Ridley's user avatar
144 votes
7 answers
182k views

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

In a PowerShell script, how can I check if I'm running with administrator privileges?
Michael Kelley's user avatar
104 votes
11 answers
139k views

How to zip/unzip files in Powershell?

Is there a one-liner that will zip/unzip files (*.zip) in PowerShell?
BlueGene's user avatar
  • 2,231
91 votes
4 answers
251k 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?
David Alpert's user avatar
  • 1,625
70 votes
5 answers
70k views

How to search Powershell command history from previous sessions

I use current Windows 10 with Powershell 5.1. Often, I want to look up commands I have used in the past to modify and/or re-run them. Inevitably, the commands I'm looking for were run in a previous or ...
shawmanz32na's user avatar
63 votes
3 answers
286k 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 processname,...
Jake's user avatar
  • 2,298
62 votes
7 answers
165k views

Windows command prompt: how do I get the output of a command into a environment variable?

I want to have an 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 ...
Tim's user avatar
  • 721
60 votes
4 answers
63k views

PowerShell script, showing commands run

I am playing around with PowerShell scripts and they're working great. However, I am wondering if there is any way to also show all the commands that were run, just as if you were manually typing ...
Nelson Rothermel's user avatar
59 votes
2 answers
48k 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 ...
Mark Allison's user avatar
  • 2,198
54 votes
5 answers
314k 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 ...
Paul Masek's user avatar
54 votes
11 answers
111k 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.
nw.'s user avatar
  • 723
48 votes
3 answers
97k views

ssh on windows - Corrupted MAC on input

I've installed OpenSSH on Windows. I can successfully connect to my remote server via ssh with Putty from this Windows machine. But when opening a PowerShell, and trying ssh [email protected] I've got ...
Raoul Debaze's user avatar
47 votes
6 answers
282k 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 ...
Brian's user avatar
  • 747
45 votes
22 answers
19k views

PowerShell? Do you use it? Can you show me some cool system administration things I can do with it? [closed]

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

Run Elevated Powershell prompt from command-line

Is there a way to run a Powershell Prompt with Elevated privileges from a command linein Server 2012? Problem is this is 'Minimal Server Interface' mode without full server-gui installed so I can run ...
NickC's user avatar
  • 2,513
42 votes
11 answers
175k views

Force-remove files and directories in PowerShell fails sometimes, but not always

I am 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:\...
Mauricio Scheffer's user avatar
38 votes
5 answers
294k views

Access network share without mapping drive letter (PowerShell)

I want to access a remote SMB network share \\SHARE-HOST\ without mapping a drive letter. I can manually do it in windows by typing \\SHARE-HOST\Share_folder\ in explorer. If I want to do it ...
ServerAdminGuy45's user avatar
36 votes
8 answers
231k 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" $...
Mark Allison's user avatar
  • 2,198
34 votes
4 answers
102k 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 ...
Doltknuckle's user avatar
  • 1,274
33 votes
4 answers
62k 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 ...
Mathias R. Jessen's user avatar
33 votes
3 answers
92k 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 ...
Mr. Smythe's user avatar
32 votes
5 answers
59k views

Managing Windows Powershell from Linux terminal

I manage Windows Server 2012 servers. I'm learning PowerShell to manage these servers through command line. My workstation runs Ubuntu and I usually manage Linux servers by connecting via SSH. Is ...
Ederson's user avatar
  • 575
30 votes
10 answers
81k views

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) without the need of the ActiveDirectory module?
Jonathan Rioux's user avatar
30 votes
8 answers
105k views

How to use a config file (ini, conf,...) with a PowerShell Script?

Is it possible to use a configuration file with a PowerShell script? For example, the configuration file: #links link1=http://www.google.com link2=http://www.apple.com link3=http://www.microsoft.com ...
Xavier C's user avatar
  • 773
30 votes
6 answers
103k 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 ...
amandion's user avatar
  • 323
29 votes
13 answers
212k 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 ...
p.campbell's user avatar
  • 4,427
29 votes
1 answer
115k views

How do I add the Windows GUI to Windows 2016 Server Core?

We just got our dedicated server from Rackspace. It was loaded with W2008 on it. I decided to put the most recent OS on it so I wouldn't have to upgrade it later. Apparently during the installation, I ...
SomeoneSpecial's user avatar
28 votes
6 answers
66k 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. ...
user avatar
28 votes
6 answers
39k views

Change the Powershell $profile directory

I would like to know how to change my the location my $profile variable points to. PS H:\> $profile H:\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 H:\ is a network share, so when I ...
Swoogan's user avatar
  • 2,097
27 votes
3 answers
15k views

How can I programmatically cause a new Windows user's profile to be created?

I'm creating a (local) user for a Windows service to run as. I've got good reasons for not wanting to use NETWORK SERVICE, LOCAL SERVICE, or LOCAL SYSTEM. I create the user via net user foobar "...
Peter Mounce's user avatar
  • 1,263
27 votes
5 answers
75k views

How do I install an app from Windows Store using Powershell

I know if I have .appx package file, I can install it via powershell with the Add-AppxPackage cmdlet. However, I simply want to download & install Microsoft Store packages by name. I don't want ...
David Wilson's user avatar
27 votes
5 answers
13k 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
Bryan Ward's user avatar
25 votes
2 answers
4k views

Is there a way to loop through 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 make Powershell to loop through all the ...
Jason's user avatar
  • 3,941
25 votes
4 answers
203k views

How to edit Local Group Policy with a script?

I have to set the local group policy settings and the the local security policy for a couple of machines which are not in a Windows domain. Until now, I've done that by manually setting the keys in ...
P. Egli's user avatar
  • 351
24 votes
4 answers
103k 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 : ...
atricapilla's user avatar
24 votes
1 answer
6k 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 ...
Ashwin Nanjappa's user avatar
23 votes
4 answers
59k views

Set service StartType to Automatic - Delayed

Using Set-Service, I'm able to change the StartType of my services between the accepted values of Boot, System, Automatic, Manual, Disabled. Using services.msc, I'm able to set some services to ...
Peter Vandivier's user avatar
23 votes
3 answers
34k views

How do I change my default PowerShell profile / digitially sign my $profile file?

I tried creating an ultimate setup for my powershell environment. I created "Microsoft.PowerShell_profiles.ps1" with a bunch of statements to setup my default profile. When I start a PowerShell ...
Brett Veenstra's user avatar
22 votes
3 answers
59k views

Add a binding to an IIS site using powershell

I'm trying to control bindings in an IIS app using powershell. I'd like to create a site with both a http and https binding using a script. This is what I have thus far: Param( [Parameter(...
Khanzor's user avatar
  • 331
22 votes
7 answers
145k views

command line - switch to administrator mode

Is it possible to switch from normal mode to administrator mode in command line? I don't want to open command line by right clicking and selecting "run as administrator". Thanks
culter's user avatar
  • 517
22 votes
3 answers
58k 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 ...
MDMoore313's user avatar
  • 5,591
22 votes
5 answers
12k views

Powershell equivalent of Ctrl+R?

In bash I can do Ctrl+R and start typing a command to have it search my history. How do I do that in powershell? Is there a way to bind a key to something like? function GH($str) {get-history | ...
red888's user avatar
  • 4,243
21 votes
2 answers
3k views

HALP! I've inherited a permissions nightmare for redirected folders/home directories

My new employer has folder redirection setup for its hundreds of users, and the person who set it up didn't really know what he was doing. As a result, the best practices for permissions on ...
HopelessN00b's user avatar
20 votes
3 answers
90k views

Change owner recursively with Powershell?

I'm trying to use Powershell to change owner of a folder, recursively. I'm basically using this code: $acct1 = New-Object System.Security.Principal.NTAccount('DOMAIN\Enterprise Admins') $...
Mikael Grönfelt's user avatar
20 votes
8 answers
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?
Brett Veenstra's user avatar
20 votes
4 answers
100k 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 ...
Rob Murdoch's user avatar
20 votes
5 answers
100k views

What version of Windows Management Framework is installed?

How do you check to see what version of Windows Management Framework (WMF) is installed? It seems like it should be a simple thing to find out, but I cannot. Even Googling a bunch of different ...
Loduwijk's user avatar
  • 565
20 votes
1 answer
29k views

Redirect standard error to a 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 ...
Matt's user avatar
  • 1,142
20 votes
3 answers
39k 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 ...
Warren P's user avatar
  • 1,195

1
2 3 4 5
83