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
11
votes
2 answers

How to export a Full SMTP Log in Office 365

In Office 365, is it possible to export the SMTP log? Maybe in powershell or any other way. My goal is to have a complete overview of all messages send from and to a specific domain.
ZEDA-NL
  • 846
  • 1
  • 6
  • 13
11
votes
2 answers

Powershell - Test user credentials in AD, with password reset

I can successfully use Powershell to tell if a user authenticates in Active Directory: Function Test-ADAuthentication { param($username,$password) (new-object directoryservices.directoryentry "",$username,$password).psbase.name -ne…
dthree
  • 367
  • 1
  • 8
  • 26
11
votes
5 answers

Why am I getting unauthorized errors with Powershell get-winevent?

I'm a domain admin equivalent, I've tried running in an elevated console (right-click> run as administrator), and I'm consistently getting errors when executing get-winevent -logname application | where {$_.message -match "Faulting application"} |…
user209162
  • 111
  • 1
  • 1
  • 3
11
votes
1 answer

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-RDSessionCollectionConfiguration -CollectionName "Example"…
11
votes
3 answers

PowerShell performance difference filter vs. function

I'm reading currently the Windows PowerShell 3.0 Step by Step book to get some more insights to PowerShell. On page 201 the author demonstrates that a filter is faster than the function with the same functionally. This script takes 2.6 seconds on…
Marcel Janus
  • 1,115
  • 2
  • 14
  • 29
11
votes
1 answer

Customizing powershell font face and size

We have a number of windows 2012 server core systems with powershell setup as the default shell using the following commands: $RegPath = "Microsoft.PowerShell.Core\Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows…
Brad
  • 619
  • 1
  • 10
  • 28
11
votes
4 answers

Protect foreach loop when empty list

Using Powershell v2.0 I want to delete any files older than X days: $backups = Get-ChildItem -Path $Backuppath | Where-Object {($_.lastwritetime -lt (Get-Date).addDays(-$DaysKeep)) -and (-not $_.PSIsContainer) -and ($_.Name -like…
SteB
  • 989
  • 6
  • 15
  • 31
11
votes
12 answers

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 don't see how I could easily use the information…
Martin
  • 243
  • 1
  • 3
  • 9
11
votes
3 answers

Powershell Parameters

I have a Param block in my script Param ( [Parameter(Mandatory=$True)] [string]$FileLocation, [Parameter(Mandatory=$True)] [string]$password = Read-Host "Type the password you would like to set all the users to"…
TechGuyTJ
  • 792
  • 1
  • 13
  • 26
11
votes
3 answers

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 "0: $($args[0])" echo "1: $($args[1])" $items =…
sbi
  • 463
  • 2
  • 4
  • 12
11
votes
3 answers

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 PowerShell Remoting.) My script works wonderfully…
11
votes
3 answers

Cannot get CredSSP authentication to work in PowerShell

In attempting to create a PowerShell script using remoting I ran into what I believe is the double-hop problem. In that article, Perriman gives a succinct description of the problem as well as the specific steps to resolve the issue (almost trivial…
Michael Sorens
  • 445
  • 2
  • 6
  • 17
11
votes
5 answers

Can't give 'send-as' permissions in Exchange 2010

I'm trying to give 'send-as' permissions to one user in Exchange 2010. Here is the Powershell command I'm running: Add-ADPermission "User1" -User "Ourdomain\User2" -Extendedrights "Send As" Powershell returns this error: Active Directory operation…
Kieran Walsh
  • 905
  • 7
  • 15
  • 31
11
votes
3 answers

Use Powershell to find out what uses lots of memory (on 64 bit Windows)

How do I find out (in Powershell) what process/whatever uses the most memory? Edit: I am trying to figure out how to use Powershell to find out what's using all the physical memory in case Task Manager etc. fail to explain why all the physical RAM…
Andrew J. Brehm
  • 1,611
  • 7
  • 37
  • 57
11
votes
2 answers

How can I tell if a user has more than one computer logging with Outlook?

I have reason to suspect that a user may be accessing their company email using a copy of Microsoft Outlook (or perhaps another email client) from a personal device for the purpose of data exfiltration. I've ruled out them accessing their account…
Jason
  • 111
  • 3