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.
4,126
questions
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 ...
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 ...
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?
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?
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?
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 ...
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,...
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 ...
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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:\...
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 ...
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"
$...
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 ...
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 ...
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 ...
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 ...
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?
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
...
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 ...
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 ...
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 ...
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.
...
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 ...
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 "...
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 ...
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
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 ...
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 ...
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 : ...
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 ...
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 ...
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 ...
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(...
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
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 ...
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 | ...
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 ...
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')
$...
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?
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 ...
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 ...
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 ...
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 ...