Automate Disable Self-Service Purchase option Office 365 Products

You have seen my previous article about how to Disabling Self-Service Purchase options.

Disable Self-Service Purchase option Office 365 Products | Tech Wizard

I am tempted to write this blog as we came across situation where we want to automate it and not checking on every few weeks and then disabling the products.

On first look it seemed to be simple, but issue is MSCommerce module does not have any option to pass PS Credentials.

We have modified the module and embedded in the script solution zip. (Reference: Providing scripted credentials or PSSession credentials for Connect-MSCommerce · Issue #799 · MicrosoftDocs/microsoft-365-docs ( )

Download the solution from below git hub link:

Downloads/ at master · VikasSukhija/Downloads (

Here are the files after extraction:

vsadmin module is required before proceeding further.

Update the batch file as shown here:

PowerShell .\disableselfservicepurchase.ps1 -smtpserver smtpserver -from -erroremail

Run it manually ones by double clicking the batch file, will auto generate encrypted password first time it is run and save it in the same folder.

After that it can be scheduled via task scheduler.

Before running the script, you can check the status of products(follow for details – Disable Self-Service Purchase option Office 365 Products | Tech Wizard)

Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase

After Script is run, it will disable the products that are set as Enabled and will also report in CSV that is saved in report folder.

Here is the Task Scheduler Settings:

Task Scheduler Settings that you should not forget is Start in (optional): should be populated with the directory from which script is running.

If you want to automate the Disable of self-service purchase options, then you are on right blog post .

Just download and schedule this script solution.


Thanks for reading and downloading…

Tech Wizard

PowerShell Fast Track


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s