Catégories
Informatique

Désactiver AllowSelfServicePurchase sur Microsoft 365

Les utilisateurs de votre tenant Microsoft arrivent à acheter eux même (et avec leurs données de paiement) des produits comme Power BI Pro, Visio, MS Project? Cela se désactive.

Activé par défaut, ce réglage uuuuuun peu chiant qui vous fait perdre la visibilité de vos licences Microsoft 365 est désactivable en PowerShell.

Alors comment faire?

On va faire deux choses, une côté MS Commerce, une côté MsolCompanySettings

Déjà vous pouvez lire la documentation Microsoft sur ce sujet, appelée « Use AllowSelfServicePurchase for the MSCommerce PowerShell module »

En effet, il y a un comportement en « self service » assez étrange dans les tenants Microsoft qui laisse les utilisateurs s’acheter des licences, ce n’est pas très pratique.

Pour avoir un état des lieux de ce qui est actif sur votre tenant, il faut commencer par installer un module.

Installez le module MSCommerce et connectez vous

Install-Module -Name MSCommerce
Import-Module -Name MSCommerce
Connect-MSCommerce

Policy AllowSelfServicePurchase

Puis maintenant c’est l’heure d’obtenir votre liste :


Get-MSCommercePolicy -PolicyId AllowSelfServicePurchase

Vous obtiendrez un résultat du type :

Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase


PolicyValue ProductId PolicyId ProductName
----------- --------- -------- -----------
Enabled CFQ7TTC0LH3L AllowSelfServicePurchase Power Automate per user
Enabled CFQ7TTC0LH2H AllowSelfServicePurchase Power Apps per user
Enabled CFQ7TTC0H9MP AllowSelfServicePurchase Power BI Pro
Enabled CFQ7TTC0HDB1 AllowSelfServicePurchase Project Plan 1
Enabled CFQ7TTC0HDB0 AllowSelfServicePurchase Project Plan 3
Enabled CFQ7TTC0HD33 AllowSelfServicePurchase Visio Plan 1
Enabled CFQ7TTC0HD32 AllowSelfServicePurchase Visio Plan 2
Enabled CFQ7TTC0KXG6 AllowSelfServicePurchase Power Automate RPA
Enabled CFQ7TTC0H6RP AllowSelfServicePurchase Power BI Premium per user
Enabled CFQ7TTC0HHS9 AllowSelfServicePurchase Windows 365 Enterprise
Enabled CFQ7TTC0J203 AllowSelfServicePurchase Windows 365 Business
Enabled CFQ7TTC0HX99 AllowSelfServicePurchase Windows 365 Business with Windows Hybrid Benefit
Enabled CFQ7TTC0HVZG AllowSelfServicePurchase Viva Learning
Enabled CFQ7TTC0LH3N AllowSelfServicePurchase Dynamics 365 Marketing
Enabled CFQ7TTC0LHWP AllowSelfServicePurchase Dynamics 365 Marketing Attach
Enabled CFQ7TTC0LH05 AllowSelfServicePurchase Microsoft 365 F3
Enabled CFQ7TTC0LHVK AllowSelfServicePurchase Dynamics 365 Marketing Additional Application
Enabled CFQ7TTC0LHWM AllowSelfServicePurchase Dynamics 365 Marketing Additional Non-Prod Application
Enabled CFQ7TTC0PW0V AllowSelfServicePurchase Viva Goals
Enabled CFQ7TTC0LSGZ AllowSelfServicePurchase Power Automate Per User with Attended RPA Plan
Enabled CFQ7TTC0J1FV AllowSelfServicePurchase Teams Exploratory
Enabled CFQ7TTC0S3X1 AllowSelfServicePurchase Python On Excel
Enabled CFQ7TTC0RM8K AllowSelfServicePurchase Teams Premium
Enabled CFQ7TTC0N8SL AllowSelfServicePurchase Microsoft Purview Discovery
Enabled CFQ7TTC0N8SS AllowSelfServicePurchase Microsoft ClipChamp

Cela vous liste les ID de chaque souscription que les utilisateurs peuvent prendre inviduellement.

Pour désactiver un seul ID , Microsoft vous donne la commande suivante en exemple :

Get-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId CFQ7TTC0KP0N

Mais si vous voulez tout désactiver d’un coup vous pouvez utiliser la boucle suivante donnée dans la Tech Community par Carl W:

$products = Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase | Where { $_.PolicyValue -eq "Enabled"}

foreach ($p in $products)

{
Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId $p.ProductId -Enabled $False
}

Réglage MsolCompanySettings

Un autre réglage à faire est du côté du réglage Set-MsolCompanySettings qui permet de désactiver les souscriptions « AdHoc »

Pour se faire, première étape, installer, importer et connecter MSOnline :

Install-Module MSOnline
Import-Module –Name MSOnline
Connect-MsolService

Puis après à vous la commande magique :

Set-MsolCompanySettings -AllowAdHocSubscriptions $false

Laisser un commentaire