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

Syncing on prem to office 365 via adconnect and migrating mailboxes to exchange online in the cloud.  I have a couple of questions:

1.  If I migrate a users mailbox, and the user does not have a license in Office 365, will the user still migrate and have full functionality with the migrated mailbox for 30 days?  After 30 days, would this go to the recycle bin and need to be restored?

2.  I am assigning licenses through msol by using a on premises group, then have a script that reads the group and if a member set's license sku's in O365.  On some occasions (small amount), the license is added to the group, and the script goes to set a license sku but this fails.  I think this is due to giving a license to the user at some point, then taking it away.  Does giving a license set any attributes in msol which would cause this?

3.  I set a SIP address for skype for business for on prem mailboxes and accounts that are syncing to O365.  I've noticed when some accounts were migrated, that skype connection was lost and I had to re-license the user.  Any explanation why this would happen.

Really appreciate any knowledge on this.

IoT Devices - Fast, Cheap or Secure…Pick Two
IoT Devices - Fast, Cheap or Secure…Pick Two

The IoT market is growing at a rapid pace and manufacturers are under pressure to quickly provide new products. Can you be sure that your devices do what they're supposed to do, while still being secure?

$Path = "$env:USERPROFILE\appdata\roaming\"


Get-childitem $Path -include $Files -recurse | foreach ($_) {remove-item $_.fullname}

Open in new window


So this is meant to delete all files associated with the above file types, it doesn't. It also doesn't pull the array correctly, it only pulls *.PDF

I'm getting rather frustrated. Could someone help again please :(
Good morning all,

OK so

There is a process our machines follow when they boot up, I need to remove an array of file types, thus I have the following script
$Files ='*.pdf','*.doc','*.dot','*.docx','*.docm','*.dotx','*.dotm','*.docb','*.xls','*.xlt','*.xlm','*.xltx','*.xlsm','*.xlsb','*.xla','*.pptx','*.pptm','*.potx','*.potm','*.ppsx','*.ppsm'

Remove-Item "c:\users\$env:UserName\appdata\roaming\Noname"

Get-ChildItem -Path 'c:\users\$env:UserName\appdata\roaming\Noname' $Files | foreach { Remove-Item -Path $_.FullName }

Open in new window

Doesn't work, nor can any amount of googling help :(

Could someone give me a hit in the right direction?

Thank you very much

Trying to get a simple list of samacvountnsme

New-item command that writes to log. And also want a friendly message to screen


{write-host ("Folder created for " + $ADUSER.samaccount)}

I get

Mode.       Lastwritetime.    Length.  Name.  

Just want the name column

{write-host ("Folder created for " + $ADUSER.samaccount) | format table name}. Doesn't do anything
I have been using this power shell command to create a text files that lists the currently installed programs on Windows 10 computers:

Get-WmiObject -Class Win32_Product | Select-Object -Property Name > C:\PCapps.txt

Open in new window

The problem is that this command lists only the names of the installed programs.

I would like to run a command that will display the complete list of everything that is displayed within the Programs and Features applet: Software name, publisher, installed on, size, & version.

What is the correct syntax of a command that will display all this information?
I am running some queries in Powershell.

I have created a function that returns an object I can use foreach (hence the return ,$table)
I first obtain a sql reader and load a data table with the returned recordset.

$rdr = $command.ExecuteReader()
 $table = new-object “System.Data.DataTable”
 $table.Load($rdr )
  return ,$table

Open in new window

The issue is that when iterating through the results I cannot perform an additional calls $command.ExecuteReader() even if I create a new command object and set the query text for that new command object.

I get the following error when I try: "There is already an open DataReader associated with this Command which must be closed first."

So I tried to close the reader after loading the data table

$rdr = $command.ExecuteReader()
 $table = new-object “System.Data.DataTable”

  return ,$table

Open in new window

With the data table filled and returned by the function, why can't I close the reader and then make a subsquent call to $command.ExecuteReader() ????
I'm working with multiple remote computers and here is what I found on a previous post and have modified but still not working hope I could get some assistance.

function Get-ServerInfo {
$image1 = "1234"
$image2 = "5678"
$computername = $_
$os = Get-WMIObject -Class Win32_operatingsystem
$system = Get-WMIObject -Class Win32_ComputerSystem
New-Object PSObject -Property @{
  ComputerName = $computername
  OS = $os.buildnumber

Get-Content c:\servers.txt | Get-ServerInfo | Format-Table -auto | export-csv c:\scripts\imagever.csv -notype

2 issues I have
1. script only gets the first wmi query of the buildnumber from the local machine, and then provides the computernames from the list
2. the variables I've declared at the top for the $image1 and $image2 I would like to put into this script once I can get it working properly to perform and if/else statement but to replace the information if it meets a specific criteria and everything I have tried thus far doesn't work

if($os.buildnumber -eq $image1) ){replace that information with 1.0}
if($os.buildnumber -eq $image2){replace that information with 2.0}
else{write-output c:\scripts\image}
Hi Experts,

I have this script tested and works as expected.  script checks the disks attached to server and checks the  drive label  of the disks and create a .txt file with the drive letter name ( such as "D drive.txt")  scripts is copied to  each server already and locally run.

For an example, if four disk found as D, E,Y,S on a local server, after running the script,  when I  go into each disk, I should have a .txt file saved in there as D drive.txt, E drive.txt , Y drive.txt and S drive.txt

batch script will be used on  mixture Windows OS versions. ( 2003 to 2012)

Issue: it works fine when script is run locally but when needed to run using PSexec, it produces different issues  even though script is on the local server and all PSexec should do is executing the script with remotely instead of logging into the each server. I have read on forums that vmic is not very friendly with PSExec, is there way to eliminate wmic from the script? here is forum talks about the issues it causes:  https://forum.sysinternals.com/psexec-hangs-when-running-wmicexe_topic14752.html

thanks in Advance
Hi All, I had this same question (Listing the Shared Network drive size (UNC path) using powershell) and the solution provided worked perfectly. My problem is the sizes are outputting as things like 4.74842E+1, etc. How do I get them converted o GBs and MBs in the output?
I had this question after viewing Powershell script to ping a list of IP address and output to file.

The former script with output file works perfectly for me except that it takes forever when it's a list of hundreds of IP addresses. Is there a way to speed this process up for large sets of IP addresses? Also, does the source file have to be a .txt file or is there a way to utilize a .csv excel file?

Thank you.
Has Powershell sent you back into the Stone Age?
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.


I am trying to update a .ini file for Microsoft's OneDrive Next Generation Client to deploy to as group of users.  I can display and edit the file in notepad fine but I cannot do it via a PowerShell script.  If I use the cmdline 'type' or PowerShell cmdlet 'get-content' to display the file it displays spaces between each character in the file. i.e. 'installID=1'  becomes 'i n s t a l l I D = 1'.  If I try to update the file it will not save.

Has anyone seen this peculiarity before?  If so, is it some kind of encoding? Can you help?

Kind Regards,

Hello everyone.

I am looking to create a small script which will remove litigation hold from a number of users at once with powershell

Get-mailbox test@contoso.com | set-Mailbox -litigationHoldEnabled $false


Would this work?

$RemoveLitigationHold = import-csv "C:\temp\Removelit.csv"
ForEach ($User in $RemoveLitigationHold) {set-mailbox -Identity $user.PrimarySMTPAddress -litigationHoldEnabled $false}
I have an application which uses the following code to import a powershell snapin (left out exception handling for brevity!!):

public static RunspaceConfiguration MyRunspaceConfiguration
public static Runspace MyRunspace = RunspaceFactory.CreateRunspace(MyRunspaceConfiguration)
MyRunspace.AddPSSnapin("WMware.VimAutomation.Core", out CustomPsException)

Open in new window

This works fine, however with a recent update to VMware software the use of snapins has been deprecated and the now modules are used instead. The advice from VMware is to use the following (in powershell):

Get-Module –ListAvailable VM* | Import-Module

The problem I have is I don't know how to achieve this line within my C# application runspace - any ideas?
I have the following script which runs against a list of machines and sets remote registry to automatic and then starts it.  i would like for the script to run faster and therefor would assume checking for the current status of the remote registry service and skipping the machine if already on would help to make it quicker.  

$computers = get-content -path "c:\temp\serversforIvanti.txt"
#$computers = Get-ADComputer -Filter { OperatingSystem -Like '*Windows Server*' } 
foreach ($computer in $computers)
if (Test-Connection -count 1 -computer $computer -quiet){
Write-Host "Updating system" $computer "....." -ForegroundColor Green
Set-Service –Name remoteregistry –Computer $computer -StartupType Automatic
Get-Service remoteregistry -ComputerName $computer | start-service
Write-Host "System Offline " $computer "....." -ForegroundColor Red
echo $computer >> ./offlineRemoteRegStartup.txt}

Open in new window


Is there a faster way to open mulitple programs using powershell in an infra desktop.

Like I want to open the list of prgrams below with their shortcuts:

"C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\Ssms.exe"
"C:\Program Files\SentryOne\11.0\SentryOne Client.exe"

Then the other like how can I open failover cluster manager since it needs to open Run then type in cluadmin.msc

And also for outlook I can't find the  shortcut
Hi All,

we are migration VMs from Hyper V to azure and after migration we need install a few agents, like montoring agent, vm agent, etc on the virtual machines.

What is the best way to achieve this? should we use powershell dsc?

Thank you in advance,
Running a script that part of it outputs the 'count' of members in a set of distribution groups, I noticed that '1' was not being outputted where all other numbers were.  The following is the output of a test on live groups (group names and members have been edited for security):-


PS S:\> $a = Get-DistributionGroupMember -Identity GroupWithOneMember
PS S:\> $a

Name         RecipientType
----         -------------
****.******* UserMailbox

PS S:\> $a.count
PS S:\> # ^--returned nothing


PS S:\> $a = Get-DistributionGroupMember -Identity GroupWithTwoMembers
PS S:\> $a

Name         RecipientType
----         -------------
******.***** User
****.******* UserMailbox

PS S:\> $a.count


PS S:\> $a = Get-DistributionGroupMember -Identity GroupWithZeroMembers
PS S:\> $a
PS S:\> $a.count
PS S:\>

So as you can see, it outputs a count of 0 and 2, but not for 1!

Thanks for any advice you can give.
I had this question after viewing Powershell to show mailbox DB .EDB size ?.


Can anyone here please assist me in modifying the below PowerShell script to calculate the Exchange Transaction log file size ?

Get-MailboxDatabase | 
    Select Server, 
           @{Name="DB Size (GB)";Expression={$objitem = (Get-MailboxDatabase $_.Identity); $path = "`\`\" + $objitem.server + "`\" + $objItem.EdbFilePath.DriveName.Remove(1).ToString() + "$"+ $objItem.EdbFilePath.PathName.Remove(0,2); $size = ((Get-ChildItem $path).length)/1048576KB; [math]::round($size, 2)}}, 
           @{Name="Number of Mbx";expression={(Get-Mailbox -Database $_.Identity | Measure-Object).Count}},
           IsPublicFolderDatabase | ft -AutoSize

Open in new window

So far it works great, but I cannot get the total Transaction Log size.

Any help would be greatly appreciated.


From the below command I got the output what I require, but I need to do this for multiple servers and also I need the server name in the output.

Get-Content \\AP0000345\F$\maint.log | Select-String 'Application Server Maintenance'

Current Output:

PS C:\Temp\MaintStage1> Get-Content \\APISEM501\F$\maint.log | Select-String 'Maintenance is Completed'

Maintenance is completed and the Server will re-boot now !...

Below we see only the text "Maintenance is completed and the Server will re-boot now !..." with out a server name, however if I run this for multiple servers I must have the server name to validate if the maintenance has been completed on that server or not.

Please help. !!!!
On Demand Webinar: Networking for the Cloud Era
On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Need some help in creating a script to set activesync devices to allow for a list of users.

What i have so far

//puts name and deviceID in to mylist variable
$mylist = Get-Mailbox -server ExServer01 | ForEach-Object {
      $Name = $_.Name
      Get-MobileDevice -Mailbox $_.Name | Select-Object -Property @{Name='Name'; Expression={$Name}}, DeviceID}

How would i use $mylist to loop through and set each users devices to allow. Below is how i would do one person.

Set-CASMailbox -Identity: "tonysmith" -ActiveSyncAllowedDeviceIDs: "<DeviceID_1>"

if there is a better way that would be great also

thank for any help
Hi I made a powershell script to create a new and default outlook profile.
When I run i from the desktop as a normal user it does what I want.
I've then created a GPO to run it at user logon but then it doesn't run.

How do I figure out what's wrong and why isn't it running?

GPO settings
User Configuration - Policies - Windows Settings - Scripts - Logon
For this GPO, Script order: Not configured
"\\domain.local\SYSVOL\domain.local\scripts\O365 new profile.ps1"
-executionpolicy bypass

The script is as follows
# O365 New Profile.ps1
# v01 July 14 2017 by Filip Heens

Add-Type -AssemblyName System.DirectoryServices.AccountManagement;
$Displayname = [System.DirectoryServices.AccountManagement.UserPrincipal]::Current.DisplayName
$O365Profile = "O365 $Displayname"

#Default Windows Settings
$registryPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\$O365Profile"
IF(!(Test-Path $registryPath))
    New-Item -Path $registryPath -Force | Out-Null

$registryPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\"
$Name = "DefaultProfile"
$value = $O365Profile
      New-ItemProperty -Path $registryPath -Name $name -Value $value …
Good afternoon experts,
I have a O365 client that appears to have had users removed from their O365 tenant when they left the company, however the users mailboxes are still in that tenant. So my question is two fold:

- 1st) Can I create a new user and associate to the orphaned mailbox somehow so I can export it down to PST and save for legal processes.
-2nd) Can I not worry about creating a user and somehow just pull the mailbox down manually via powershell or preferably the O365 admin portal.

Thanks for your help,

Hello folks,
I need to create a shortcut by using a script batch or PS1 or vbs, I have found this for now but it will not give me a ie

echo start http://www.google.com > "%userprofile%\desktop\Google.cmd"

does anybody has a better solution ?

does anyone have a power shell script i can use to check my pc's to see what version of IE they are running?


I have this powershell script:

Get-qadcomputer kellytestmachine | select Name, OSName, OSServicePack, ComputerRole, dNSHostName

all the items that are selected, I want them to be a different name for the csv file.

so I tried this for test however it failed:

Get-qadcomputer kellytestmachine | select Name, OSName, @{n="OS Service Pack";e={"$_.OSServicePack"}}, ComputerRole, dNSHostName

Thank you in advance






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.