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

I'm kinda of stuck on this one
Trying to get an excel macro to kickoff via powershell script from a windows scheduled task

#requires -version 3

    Automate and schedule execution of excel macros non-interactivley

	Sets excel dcom config to interactive and execute excel macro on worksheet 1

    Mandatory parameter indicating macro to run

.PARAMETER xlsmfile
    Manadatory parameter indicating excel file which is running the macro

	powershell.exe .\ExcelMacro.ps1 -macro "CreateChart" -xlsmfile "C:\fso\Book1.xlsm"

	 Created on:   	6/27/2017 12:43 PM
	 Created by:   	Mauro Cazabonnet
	 Organization: 	InfoHedge Technologies
	 Filename:  ExcelMacro.ps1   	

Param (
	[Parameter(Mandatory = $True, Position = 1)]
	[Parameter(Mandatory = $True, Position = 2)]

#region Set excel macro settings
$version = 0
dir HKLM:\software\Microsoft\Office | %{
	if ($_.name -match '(\d+)\.')
		if ([int]$matches[1] -gt $version)
			$version = [int]$matches[1]
$Regkey = "HKCU:\Software\Microsoft\Office\$version.0\Excel\Security"
Set-ItemProperty -Path $RegKey -Name VBAWarnings -Type Dword -Value 1

#region Set Excel DCOM config 

Open in new window

Technology Partners: We Want Your Opinion!
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Dear Team,

Please provide a script that can create folder and sub folders from the exported CSV file (using power Shell).

I have a company file server, I want to replicate the same directory with different company name (without files) and different permission group name on the same server.

I want to edit company directory name from the exported csv file and also edit the permission group names.

For example from one script, it will export the folder directory name and permission details to a CSV file, Then we can able to edit that CSV file, after that the second script can import, create folders and apply permission according to the importing CSV file.

Highly appreciate your favorable response in this matter.
Good morning,

I've got a problem with the country name in Active DirectoRY.
When I create an account with the country digit (FR or UK for example) with PowerShell, the name doesn't appear in Outlook or in "co" or "countrycode" in LDAP.

I saw it's normal because I need to enter the 3 informations in my script.

So, I would like to export the list of country, countrycode and country digit to use the same as my AD.
I found a list on Wikipedia and on https://www.iso.org/obp/ui/#search but they're not the same.

Was it possible to export all of this informations from Active Directory ?

Thank you for your help.


Can you help, I have a powershell script that will query a SQL file given the list of servers if the Events exist or not or if it is running or stopped. I already have the code but not getting what my expected format in csv. See the code below:


$ExecuteQuery= Get-Content -path $QueryPath | out-string

“Results — > `r`n`r`n” > $OutputFile

FOREACH($server in GC “CC:\DBA\EE\Server_List.txt”)
“——————————-” >> $OutputFile
$server >> $OutputFile
“——————————-” >> $OutputFile
invoke-sqlcmd -ServerInstance $server -query $ExecuteQuery -querytimeout 60000 | ft -autosize | out-string -width 4096 >> $OutputFile

Open in new window

Actual Result:
Preferred Result:
Note: Can you also remove in the output the words Result(Results — > ) and the ServerName on the Actual Result since it is already showing the ServerName(Server1\Instance1)
I recognize the official word from Microsoft is:

If a smart hosted SMTP Send Connector has multiple smart hosts defined, load balancing and fault tolerance are accomplished using these smart hosts.

but what does that mean.  Is there a round robin?  What does load-balanced specifically mean in this case?

Thank you.
How can I run powershell commands in the backend that will allow users to enter Data in a GUI pop up box? For example:

Set-MsolUserPrincipalName -UserPrincipalName <    >  –NewUserPrincipalName <   >
I need a script to get all versions of IE installed in Domain.   This script throws the following error.

$array =@() 
$keyname = 'SOFTWARE\\Microsoft\\Internet Explorer' 
$computernames = Get-Content C:\Computer.csv 
foreach ($server in $computernames) 

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server) 
$key = $reg.OpenSubkey($keyname) 
$value = $key.GetValue('Version') 
 $obj = New-Object PSObjec
        $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $server 
        $obj | Add-Member -MemberType NoteProperty -Name "IEVersion" -Value $value 
        $array += $obj  

$array | select ComputerName,IEVersion | export-csv IE_Version.csv


You cannot call a method on a null-valued expression.
At line:8 char:1
+ $value = $key.GetValue('Version')
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
Exception calling "OpenRemoteBaseKey" with "2" argument(s): "Attempted to perform an unauthorized operation."
At line:6 char:1
+ $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + …
Hi There,

I am looking to create a powershell GUI for exchange calendar permission, this will help me a lot.

currently i am using below command to give permission.  Powershell script GUI should be able to assk the user details and access rights.
Set-MailboxFolderPermission -Identity “UserA:\Calendar” -User “UserB” -AccessRights Editor

Dear experts,

I'm newbie to scripting so as always your help and time is very appreciated.

on source infrastructure : I have server1 on domain A with lots of local groups. all these local groups on server1 has domain groups and user members. it is a standalone windnows 2003 server.

on target infrastructure: I have domain B with windows 2012 server.

findings: I found below script on TechNet but slightly confused about copying nested members or group members to target DC. I could not understand on which line it is copying  group members to domain B domain Controller after creating Universal or Domain Groups on Domain controller. Surely, created groups must have their members.  


task completed: I used basic bat file on source server to get local groups and their members. For an example:  net localgroup "Administrators" >> GroupMembers.txt   this gave me the outcome I need but it I need to sort it correctly so that when I use it to import the outcome sorting should be easy to collect for the PowerShell mentioned in the link. I did NOT use POWERSHELL on Source Server.

question: I need to move all the local groups and their members from server1 domain A to Domain B Doman controllers so all groups are domain based groups instead of local groups as it is now in domain1 on Server1. Is this possible to achieve this with the script found in the below link? Is there any …
Hi expert

How to automate by using powershell scripts for SFTP?

The objective is to pull the file from the remote server and upload in the fileserver.
Get your Conversational Ransomware Defense e‑book
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Hi guys,

I cant seems to find the root cause of this error

Get-MsolPasswordPolicy : Unknown error occurred.
At line:1 char:1
+ Get-MsolPasswordPolicy
+ ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (:) [Get-MsolPasswordPolicy], MicrosoftOnlineException
    + FullyQualifiedErrorId : Microsoft.Online.Administration.Automation.DomainNotRootException,Microsoft.Online.Admin

Anyone met with this before? Is it because the domain name is not the root domain as I am trying to get the password policy for the sub domain.
Dear Expert

I would like to use group policy to to run powershell to edit registry
The following is where am i up to...
1. The powershell "outlooksec.ps1" can run successfully manually on my PC to edit registry.
2.  By checking gpresult /R, the gpo is already upated on my pc.
3. the PS file is in the OUTLOOKSEC.TXT

I can't figure out the issue
Please kindly let me know what is the problem with powershell running under GPO

GPO Setting is in the GPOSETTING.BMP

The ps1 itself is ok, it just done run
like (Ex: if i pass CTF Xid it will create SPXid and Result-Xid) if i pass one column it will create total 3 .....through PowerShell Scripting i want
Hi All,

Suppose I'd like to add the existing production mailbox database copies from one server to another, does the below PowerShell is correct ?

These are the below Exchange Server 2013 Standard Edition that I've got:

AD Site:Default-First-Site-Name
PRODMAIL20-VM [Mailbox & CAS]
C:\ OS - 200 GB
D:\ PRODMAIL20-VM-DB01 - PRIMARY [DB & Logs] 999 GB
E:\ PRODMAIL20-VM-DB02 - PRIMARY [DB & Logs] 999 GB

AD Site: Head Office
PRODMAIL30-VM [Mailbox & CAS]
C:\ OS - 200 GB
F:\ PRODMAIL30-VM-DB01 - PRIMARY [DB & Logs] 999 GB
G:\ PRODMAIL30-VM-DB02 - PRIMARY [DB & Logs] 999 GB

#Adding Mailbox DB copy and manually start the DB replication after hours
Add-MailboxDatabaseCopy PRODMAIL20-VM-DB01 -MailboxServer PRODMAIL30-VM –SeedingPostponed
Add-MailboxDatabaseCopy PRODMAIL20-VM-DB02 -MailboxServer PRODMAIL30-VM –SeedingPostponed

Add-MailboxDatabaseCopy PRODMAIL30-VM-DB01 -MailboxServer PRODMAIL20-VM –SeedingPostponed
Add-MailboxDatabaseCopy PRODMAIL30-VM-DB02 -MailboxServer PRODMAIL20-VM –SeedingPostponed

Open in new window

# Resume replication afterhours
Resume-MailboxDatabaseCopy -Identity PRODMAIL20-VM\PRODMAIL20-VM-DB01
Resume-MailboxDatabaseCopy -Identity PRODMAIL20-VM\PRODMAIL20-VM-DB02
Resume-MailboxDatabaseCopy -Identity PRODMAIL30-VM\PRODMAIL30-VM-DB01
Resume-MailboxDatabaseCopy -Identity PRODMAIL30-VM\PRODMAIL30-VM-DB02

Open in new window

# Suspend replication afterhours
Suspend-MailboxDatabaseCopy -Identity PRODMAIL20-VM\PRODMAIL20-VM-DB01
Suspend-MailboxDatabaseCopy -Identity PRODMAIL20-VM\PRODMAIL20-VM-DB02
Suspend-MailboxDatabaseCopy -Identity PRODMAIL30-VM\PRODMAIL30-VM-DB01
Suspend-MailboxDatabaseCopy -Identity PRODMAIL30-VM\PRODMAIL30-VM-DB02

Open in new window

Because I get confused myself since the Exchange Console GUI http://msexchangeguru.com/2014/03/21/e2013sp1-ip-less-dag/ must specify Number in the Activation Preference number.

WHat's the best way to specify that number for all Passive copies of mailbox database ?
A past IT person has enabled Windows Power Shell scripts (with .PS1 extensions) to run with full unrestricted access on an organization's Windows 10 computers.

None of these computers are added to a domain.

What is the best method to use to disable these Power Shell scripts so that they will no longer be able to run?

We don't want to take any chances with viruses or malware exploiting this security hole.
I am getting below error after I patched Win208 R2 servers.  

attempting to perform the initializedefaultdrives operation on the "filesystem" provider failed

I did removed the patches which were installed but it still gives the error.  Unable to figure out what specific patch initiated issue.  Do anyone knows this error and any hotfix for the same released by MS?
In need to get a fix for this issue on priority.
trying to prepare a form which can be reused for any project to re-validate the credential with one-time-saved credentials...

it should save the credentials locally and next time when same user try to login the credentials it should auto use the locally stored/cached credentials...

don't know where it is going wrong but really appreciate if you could help me fixing it.

I am working on a powershell script to take this command.

Get-WmiObject -Class Win32Reg_AddRemovePrograms | Select-String -Pattern "exchange"

and if it equals this:

\\A01344\root\cimv2:Win32Reg_AddRemovePrograms.ProdID="Microsoft Exchange v14"

Then do nothing.

But if it does not equal that then run a reg file.

I am new at this please assist. Thank you in advance.
I have a website running on server 2012 using IIS. I want a contact page to send emails to a distribution group. It is all internal, we have an smtp relay server. As I have searched around to find examples I keep finding commercial stuff. I am hoping to be able to use powershell to send the email. I currently am using mailto, so it uses the users default email client, filling in to and subject and body. I would much rather have it send from the server, and not use the client. Can anyone point me at an example?
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.

is it possible to get corresponding email attribute from object property of user
I'm trying to open two PowerPoint files from powershell and sync then together. Then I have to create a loop that checks to see if there has been an update to the files every hour and if so it will update them.

So far I have assigned the source file and prompted the user to enter the file path, and then used Invoke-Item to open it; however it only opens up to display the files and not automatically open them. Any advice would be appreciated.
I am working on a project where we need to identify Shared Mailboxes that are still in use. We run Outlook 2010 and Exchange 2013. I don't know whether Mailbox auditing is on or off, I would assume its currently off as per the default

There are a large number of these Shared Mailboxes so becoming a member of the group and adding it into Outlook as a new mailbox is not going to be an easy task

We have limited tools available to us and no budget available to buy any at the moment.

The options for tools is currently:

We can run Powershell scripts and we could install the Exchange cmdlets
We might be able to download free software
How would I convert the CSV from this line of code to an HTML file? Inside of Powershell.

Invoke-SelfSearch -ExchHostname outlook.office365.com -Mailbox user@domain.onmicrosoft.com -Remote -OutputCsv archive.csv -Terms *

So, apparently Microsoft has pushed out an option on Office 365 e-mail that allows people to give a thumbs up or "like" e-mails people have sent. So far, I haven't found anyway to turn this feature off. All of the articles I've read are people asking how to turn it off but no one has an option yet, even through powershell. Is this an unkillable feature?

Here is what I'm referring to if you don't know: https://support.office.com/en-us/article/Like-an-email-message-in-Outlook-on-the-web-for-business-cfd919a9-7c3e-40ed-a6e6-aabd7d2d2acb?ui=en-US&rs=en-US&ad=US
HI All,

I have this powershell script and I need find a secure way of storing the password. I've tried :

$response = Read-host "What's your password?" -AsSecureString 
$Password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($response)

Open in new window

and this will not work.

below is my script, how do I load the assembly, it prompts and error saying :

Unable to find type [Microsoft.VisualBasic.Interaction]. Make sure that the assembly that contains this type is loaded.
At line:1 char:1

this is the code
#Specifiy Local admin account name
$user = "mcadmin"
Add-Type -Assembly System.Web
NET USER $user "$pass" /ADD /y
#Add user to local admin group
NET LOCALGROUP "Administrators" "$user" /add
#set password to never expire
WMIC USERACCOUNT WHERE "Name='$user'" SET PasswordExpires=FALSE
Write-Host "Username: $user" -foregroundcolor green -backgroundcolor black
Write-Host "Password: $pass" -foregroundcolor green -backgroundcolor black
Write-host "Server: $env:computername" -foregroundcolor green -backgroundcolor black

# Load the classes from KeePass.exe:
cd "\\smile01\Infrastructure\KeePass-2.34" | out-null
(Get-ChildItem -recurse $script:myinvocation.mycommand.path | Where-Object {($_.Extension -EQ ".dll") -or ($_.Extension -eq ".exe")} | ForEach-Object { $AssemblyName=$_.FullName; Try {[Reflection.Assembly]::LoadFile($AssemblyName) } 

Open in new window







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.