Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hello Experts - I'm trying to figure out a powershell command that will grant reviewer permissions to a conference room calendar (which is setup as a resource) for a specific group of users.  I've done this on individual user accounts using the following but get an error with this account:

Add-MailboxFolderPermission "Media Conference":\calendar -AccessRight reviewer -User "Media Office"

I get the error:  A positional parameter cannot be found that accepts argument :\calendar

I'm guessing this is because the object is a resource but I'm not sure, can anyone help with the syntax?
Will You Be GDPR Compliant by 5/28/2018?
Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

XML in Powershell for beginners :)

I have the following XML structure:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<roles version="2.0">
	<role id="7722" name="System1">
		<system permission="allow"/>
		<folders permission="allow"/>

Open in new window

(read XML)

How do I add a role? (including childs)

How do I delete a role? (including childs)

(and save to file)

Thanks in advance

My powershell-fu is weak, I work primarily with Linux but we took on an exchange project. I'm having issues connecting to a server over a vpn with powershell. My machine is a non-domain machine. The remote machine is running Windows Server 2012. I need to run a powershell script on a remote machine, RDP is not enabled, the client will not enable it, i cant copy and paste via the console on vmware so I'm left with powershell which the client assures me is what he uses to interface with the machine. i can get it to prompt me for a password for my user account but when i enter it i get:

Enter-PSSession : Connecting to remote server ***SERVERNAME*** failed with the following error message : The WinRM
client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer
is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the
TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts
list might not be authenticated. You can get more information about that by running the following command: winrm help
config. For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:1
+ Enter-PSSession -ComputerName ***SERVERNAME*** -Credential abc.net ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (***SERVERNAME***:String) 

Open in new window

How to install RSAT in WIndows 7 using command line. ? I have issue where after installing the kb for the RSAT for Windows 7sp1, when I do appwiz.cpl and see the OptionalFeatures where you can select to add or remove features in Windows 7, the thing comes up as blank. So even though I installed the kb update for the RSAT (to use aduc in windows client) I can't actually launch dsa.msc because it needs to be "activated" via the Programs and Features Optional Features portion... but that part is coming up completely blank. Is there a way to trigger the activation via powershell or command line instead of using GUI?
Hi Experts,

I need some help with getting the script to grab all users with a mailbox or smtp address in the script below.  

Now, I have to first export all users separate, filter out those without mail, and use the file with samaccountname to run the script.

This also takes an enormous amount of time to run, so any suggestions or tips are apprecaited!

I first connect to MSOL, Exchange online in shell, then run:

$Date = Get-Date
$strDate = "{0}{1:d2}{2:d2}_{3:d2}{4:d2}" -f $date.year,$date.month,$date.day,$date.hour,$date.minute

$strOutputFile = "C:\temp\licensereport.csv"

$strInputFile = "C:\temp\Licensing\input.txt"
$strSANs=Get-Content $strInputFile 

$strAccountHeader = "SamAccountName,DisplayName,UserPrincipalName,DistinguishedName,Enabled,LastLogonDate,HomeDirectory ,ScriptPath"

$strOrganizationHeader = "Company,Department,Title,Manager"

$strCommunicationsHeader = "TelephoneNumber,OfficePhone,EmailAddress,msExchRecipientTypeDetails,msRTCSIP-PrimaryUserAddress"

$strMSOL = "IsLicensed,BlockCredential,AccountSKUIds,LicenseReconciliationNeeded"

$strHeader = $strAccountHeader +","+ $strOrganizationHeader +","+ $strCommunicationsHeader +","+ $strMSOL

    Add-Content $strOutputFile $strHeader
    Write-output $strHeader

foreach ($strSAN in $strSANs)
$ADUser = $null
$ADUser = Get-ADUser -Identity $strSAN -properties *

$strAccount = $null
$strAccount = $strSAN +","+ '"'+$ADUser.DisplayName+'"' +","+ $ADUser.UserPrincipalName +","+'"' + 

Open in new window

I would like to create a Powershell script to copy folders and files from a domain computer to a non-domain computer.


Domain computer name is: "DName"
Domain user is: "Domain\DTest"
Password is: "domainpass"
Source Folder Path: "C;\TestFolder\"

Non-Domain computer name is: "LName"
Non-Domain user name is: "LName\myname"
Non-Domain password is: "localpass"
Destination Folder Path: "C:\TestCopy\"

I have tried a few attempts with no luck.

Any help is greatly appreciated.

We have a Throttling Policy in Exchange 2010 that sets the RecipientRateLimit to 1000.  We have a user that got a virus and was sending tons of emails.  Well he hit the rate limit and now is unable to send email for 24 hours.  

Now that we've cleaned up his device and changed his password, is there a way to reset the RecipientRateLimit count for this individual?

Hi All,

I have these three commands that i am trying to script:

.\emcopy64.exe \\sreadvfile03\f$ \\sreadvfile02\g$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_fdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt

.\emcopy64.exe \\sreadvfile03\e$ \\sreadvfile02\f$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_edrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt

.\emcopy64.exe \\sreadvfile03\z$ \\sreadvfile02\h$ /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:sreadvfile03_zdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt

Open in new window

so far my solution is:

$copy=@(@{source="\sreadvfile03\f$";destination="\\sreadvfile02\g$"}, @{source="\\sreadvfile03\e$";destination="\\sreadvfile02\f$"},@{source="\sreadvfile03\f$";destination="\\sreadvfile02\g$"}) 

foreach ($m in $copy){

.\emcopy64.exe $($m.source) $($m.destination) /o /s /de /secforce /purge /cm md5 /r:1 /w:1 /c /log:$($m.source)_fdrive_$(Get-Date -format "dd-MMM-yyyy_HH:mm").txt


Open in new window

will the above work?

Also how do i select the correct drive in $($m.source)_fdrive_$

also any other ways of doing as this as i am trying to master powershell?
I want to find how DNS is setup for scavenging, is there any small Powershell scripts to get an overview of how DNS is run, windows 2008\2012r2 environment
Powershell Script to get mailbox size in MB for list of users in a CSV file with only Samaccountname
Hire Technology Freelancers with Gigs
LVL 12
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Hello experts,

I need to list accounts which matches the following filter:

Enabled = True and
If the employeetype attribute  contains any values with A* (A1, A2, A3...), B* (B1, B2, B3...), C* (C1, C2, C3....), D* (D1,D2,D3,....)

EmployeeType - A*, B*, C*, D*

$UserList = Get-AdUser -Filter ( ) and -Enabled

Please assist.

Thank you.
Dear expert

I need help with code below. Script does stop all the service that have name: Apsvx*
Now I have permission problem running this, now I do have a administration rights account, but this code is running in a program that runs using a user rights permission.
However I come up a workaround! If you first create a variable name: $credential with administration rights account login info and below code run as that, then it would work.

Anyone know how to do that?

Get-Service -DisplayName Apsvx* -ComputerName ServerIP | ForEach-Object {
	$result = $_ | Select Name, DisplayName, Status, Result, Error
	Try {
		Stop-Service -InputObject $_ -ErrorAction Stop
		$result.Result = 'STOPPED'
	}Catch {
		$result.Result = 'FAILED' }

Open in new window

Need to monitor ZIP files that are older than 3 hours. I have the following code can someone let me know if will work ?

param([string]$path, [int]$minutes)
    $LastWrite = $(Get-Date).AddMinutes(-$minutes)
    $FileArray = $(Get-ChildItem $path | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $LastWrite })
    if ($FileArray.Count -eq 0)
        $msg = "No files found over $($minutes) 3 hours old"
        $msg = "$($stat) files found older than $($minutes) hours: "
        foreach ($file in $FileArray)
            $msg+=" " + $file + ","

Write-Host "Statistic: $stat"
Write-Host "Message: $msg"

exit 0

Open in new window

And, this is how i run it
PS C:\Scripts> .\FileAgeMonitoringWildCard.ps1 "\\SERVER\d$\InetPub_Test\KSFTPWebService\*.zip", 180
Statistic: 0
Message: No files found over 0 3 hours old

Open in new window

Eventually, i need embed this script into solarwinds.

Thanks for your help,
Hello ,
I have a folder with .jpg files inside. The files are pictures of users  and are named using their correspondent "ext attribute 1" .  I have also exported to a csv file all users inside an OU with Name, SamAccountName, extAttribute1.  extAttribute1 has 7 digits.  
Now, I need to for all files in the folder that have a file name with 7 digits to rename it to it's correspondent SamAccountName . If file name exists with SamAccountName, overwrite it.
I have several powershell commands to obtain .csv with the files name and the other mentioned before with AD account information for users in OU.
Can someone help me to achieve this.
Hey, Good day,

My AD has 50 OU at least.

I need a command to know how many users and desktop computers exist in each one.

How can I do it?
I am trying to create a backup power shell script that copies a directory to a server. I also want the script to check the directory and delete any folder older then, lets say 5 days. The script is set up to run daily saving the backup as the the current date. The problem that I am having is that, when the script starts to run, it checks the sub directories of all folders in that directory and deletes any file that modified time is over 5 days even on folders that were just created. Is there any way to have this script only check the root directory and delete it without it drilling down to sub directories and deleting child items from newer backups? Below is my current script.

robocopy "\\Server\Directory" "E:\Backup\$([datetime]::now.ToString('yyyy-MM-dd'))" /e /w:5 /r:5
# Delete all Files in E:\Backup older than 1 day(s)
$Path = “E:\Backup”
$Daysback = “-1”
$CurrentDate = Get-Date
$DatetoDelete = $CurrentDate.AddDays($Daysback)
Get-ChildItem $Path | Where-Object { $_.creationtime -lt $DatetoDelete } | Remove-Item -whatif -Confirm:$false

How can I achieve this (want to filter out status out of get-service but do not want to use get-service | select-object name,displayname

 get-service | Where-Object -NE status

Thanks for your input.
Dear expert

I would like to use robocopy to copy multiple folders to one destination.

I tried with powershell, but it didn't work what I mean by didn't work is the folder did not copy to destination.


$what = @("/E")
$options = @("/R:0")

$cmdArgs1 = @("$source1","$dest",$what,$options)
robocopy @cmdArgs1
$cmdArgs2 = @("$source2","$dest",$what,$options)
robocopy @cmdArgs2
$cmdArgs3 = @("$source3","$dest",$what,$options)
robocopy @cmdArgs3

Open in new window

Is there a way to administratively run a PowerShell script to delete a specific Outlook Task sent out to a subset of users?  

Thanks in advance.
We Need Your Input!
We Need Your Input!

WatchGuard is currently running a beta program for our new macOS Host Sensor for our Threat Detection and Response service. We're looking for more macOS users to help provide insight and feedback to help us make the product even better. Please sign up for our beta program today!

System: Dynamics 365 | Windows 2012 R2

I configured ADFS 3.0 and I am working on the Claim-Based Authentication,  I am getting the error below when browsing the ADFS Xml:

There was an error in enabling endpoints of Federation Service. Fix configuration errors using PowerShell cmdlets and restart the Federation Service.

I restarted the CRM server and the ADFS service but it still shows the error.  I am working on using PowerShell but cant find the ADFS 3.0 snap-in on the CRM server

I'm using psnmap to scan a remote pc via powershell (for some ports).

That works fine when I use Invoke-PSnmap -ComputerName computer01 -Port 3389,5985
but when I want to do this via a popup, it does not work (it does work with only one port).

This is what does NOT work (multiple ports):

                Add-Type -AssemblyName Microsoft.VisualBasic
            $Ports = [Microsoft.VisualBasic.Interaction]::InputBox('Enter port to scan', 'Portscan', "3389,5985")
            $Result = Invoke-PSnmap -ComputerName computer01 -Port "$Ports"

It says the value for $ports is not ok.

Please advise howto approach.
Does Exchange 2010 log in the event logs, or other log when a Public Folder is created?
Platform: Exchange 2013 Powershell


I would like to use Exchange Powershell to give me a list of all people that are in an Exchange Database in a specific format.  
For instance, I would like the command to show me "Here are the employees that are in Database1".  Here are the 2 requests:
1.  It needs to be exported to a CSV file
2.  It needs to show their email address, first name, last name, username, and display name.  

Any help would be greatly appreciated!  Thank you.
I want to run a powershell script at startup on some win10 machines that backs up many GB of data. I don't want to delay logon until this script ends so is there a way (apart from a shutdown script) where this script can run hidden in the background?
There is an application in the environment that sends out a thousand messages each month via SMTP on a scheduled date and time.  I have been asked to verify that every message has arrived and been processed successfully by the Exchange servers (the SMTP server has, in the past, encountered issues forwarding mail).

Is there a log file on the Exchange servers somewhere that contains metadata information that I can query via PowerShell?

I don't want to check every mailbox in the environment to see if it contains a specifically worded message, since that message can be deleted by the recipient upon arrival -- not to mention the time and resource utilization that would be required.  

Any thoughts or suggestions on how to make this happen?






Windows PowerShell is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework. PowerShell provides full access to the Component Object Model (COM) and Windows Management Instrumentation (WMI), enabling administrators to perform administrative tasks on both local and remote Windows systems as well as WS-Management and Common Information Model (CIM) enabling management of remote Linux systems and network devices.