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.

PowerShell exists to create a more powerful shell than Command Prompt, a more capable language than VBScript, and an environment with built-in support for remote servers and code documentation. Since its introduction, Microsoft added support for PowerShell scripting to many of their core products.

This comment by Jeffrey Snover, one of the original designers of PowerShell, explains the ideas and intent behind the language, and why it was developed instead of porting something like Bash from a Unix environment.

PowerShell provides a vastly improved scripting environment for Windows compared to previous .bat and .vbs methods; it includes PowerShell ISE - an editor and debugging environment, on the language side it has easy support for using lists, hashtables and regular expressions for pattern matching, as an interactive shell it has tab completion for command parameters and interactive help via Get-Help, and it can natively work with COM objects, WMI, registry values, call out to any .Net Framework method or library, and create and use modules written in PowerShell code.

Microsoft Software that supports PowerShell for management includes: Windows Server (and many roles and features - Active Directory, IIS, DNS Server), Exchange Server, SQL Server, SharePoint Server, Windows Azure, and Office 365 components. Here is a full list of PowerShell modules included in Windows Server 2012 and Windows 8.1.

First released in 2006 as a downloadable addition to Windows XP and Server 2003, PowerShell has been significantly upgraded in 2009 (v2) with the addition of remote execution of scripts, and in 2012 (v3), 2014 (v4), and 2016 (v5). In 2018 Microsoft released PowerShell Core (v6) which was open sourced and runs cross-platform on Windows, Mac, and Linux.

4084 questions
2
votes
3 answers

PowerShell filter files by date in name

I have many files with different names per day. How can I filter them by the date in their name? For example: app_20130505.log app_20130506.log app_20130507.log app_20130508.log app_20130509.log And my code snippet: $RetainedDays = 7 $FileNameRegex…
gazsiazasz
  • 133
  • 1
  • 5
2
votes
2 answers

PowerShell to reset local Administrator account password. 5% failures

I have the responsibility for changing the local administrator account password on my environment of 16,000 servers; I wrote a PowerShell script, but it took too long, so I added multi-threading using the powershell runspace factory to break out the…
Tim Wilde
  • 33
  • 1
  • 5
2
votes
1 answer

Exchange: exporting and deleting items

How would I safely export data from Exchange 2010 mailboxes to PSTs using New-MailboxExportRequest and have the exported items deleted from the source mailbox? The Powershell cmdlet seems to be missing the -DeleteContent switch which has been part…
the-wabbit
  • 40,737
  • 13
  • 111
  • 174
2
votes
1 answer

Reauthenticate a Remote Connection via PowerShell Script

I have a PowerShell v1 script that connects to a remote server via UNC path. After a reboot, authentication is needed because Windows apparently will not remember so the script cannot connect to the remote server How is this situation handled…
Slinky
  • 1,027
  • 3
  • 15
  • 26
2
votes
1 answer

PowerShell - Combining Sort-Object to list of piped commands

I need to process files in order from oldest create date to newest. I found the sort-object command which is what I need however I don't have a clue how to add it to my ForEach() statement. Can someone show me how to do it? Thanks Get-ChildItem…
Slinky
  • 1,027
  • 3
  • 15
  • 26
2
votes
2 answers

PowerShell v1 Move-Item not Moving items

I have a script (pasted below) that's supposed to do the following: Loops and grabs all files that match a defined pattern Copies those files into another location Move the original source file into another location (if copy was successful) It's…
Slinky
  • 1,027
  • 3
  • 15
  • 26
2
votes
2 answers

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 bulk change those users' Home Folder paths (and…
j7wb
  • 21
  • 1
  • 1
  • 3
2
votes
1 answer

Alternative for Obsolete -VhdDestinationPath Parameter

I am trying to import a virtual machine with PowerShell and I want to specify which folder the VHD file should be placed in. According to http://technet.microsoft.com/en-us/library/hh848495.aspx the -VhdDestinationPath parameter is obsolete.…
2
votes
1 answer

Powershell V1 v V3 - Pop-Up windows gone

When I did $name = Read-Host 'What is your name?' in Powershell V1 it would ask the question in a pop-up window. With Powershell V3 it just asks in the console window. Is there a way to force Read-Host questions to pop-up still?
finisterre
  • 305
  • 1
  • 3
  • 11
2
votes
1 answer

Powershell - how to Start-Job with an ActiveDirectory credential

My client controls access to their database with ActiveDirectory. I would like to do the following: $cred = Get-Credential Start-Job -Credential $cred { #do some stuff with the db } This works fine for any local user but when on the vpn and…
2
votes
2 answers

I need to list all users in Active Directory that do not have any data in the NAME field, using PowerShell

I need to list of all users in AD that do not have any entry in the NAME field (example: smith,jon) So far I have something like below Get-ADUser -filter {Name -eq " "} | FT SamAccountName I know this fails because of the empty quotations.…
Perry
  • 21
  • 1
  • 2
2
votes
1 answer

How Can I Source My $Profile From A Powershell Function?

I like to make a lot of changes to my $profile file. After saving a change, I would like to source the file using an "sop" alias. Here's how I hope to accomplish that: set-alias sop Source-Profile function Source-Profile { . $profile } This…
Tom Purl
  • 549
  • 1
  • 3
  • 13
2
votes
1 answer

Discrepancy between Event Log taken from Powershell and with Event Log Viewer

Domain Controller OS - Window Server 2008 R2 Please see the First PrintScreen attached (Powershell.png). with the help of Powershell command I am trying to check the event Log of my DC. Please note the Red Rectangle Colour Box. Failure Reason:…
Param
  • 1,357
  • 14
  • 36
  • 52
2
votes
2 answers

Trying to set COM+ application component properties in PowerShell

I have this script where I'm trying to set the IISIntrinsic property for components of an application in Com+ in Component Services. This is what I'm trying to tick Here's my powershell script: $comAdmin = New-Object -comobject…
Nils
  • 195
  • 1
  • 4
  • 13
2
votes
1 answer

How to give "only append" access to user in windows , for logging purposes

I have a powershell script which takes some data and dumps into a logfile whenever its executed.The script resides in single location and shortcut is distributed to all. I want to log the events on the script when it's executed; How can I give the…
Darktux
  • 827
  • 5
  • 21
  • 36