針對 MSCommerce PowerShell 模組使用 AllowSelfServicePurchase

MSCommerce PowerShell 模組現在可在 PowerShell 資源庫 上使用。 模組包含 AllowSelfServicePurchasePolicyID 參數值,可讓您控制組織中的使用者是否可以自助購買 Microsoft 或選取第三方供應專案。

您可以使用 MSCommerce PowerShell 模組來:

  • 檢視 AllowSelfServicePurchase 參數值的預設狀態—不論是否啟用、停用或允許在沒有付款方式的情況下進行試用
  • 檢視適用產品清單,以及是否啟用、停用或允許在沒有付款方式的情況下試用自助式購買
  • 檢視或修改特定產品的目前設定,以啟用或停用它
  • 檢視或修改不含付款方式的試用版設定

需求

若要使用 MSCommerce PowerShell 模組,您需要:

  • Windows 10 或更新版本的作業系統。
  • PowerShell 5 或以下版本。 此課程模組目前不支援 PowerShell 6.x/7.x。
  • 租用戶變更 MSCommerce 產品原則的全域或計費系統管理員角色。
  • 租使用者的全域讀取者角色,可查看 MSCommerce 產品原則的唯讀清單。

安裝 MSCommerce PowerShell 模組

您會在 Windows 10 裝置上安裝 MSCommerce PowerShell 模組一次,然後將它匯入您啟動的每個 PowerShell 會話。 從 PowerShell 資源庫 下載 MSCommerce PowerShell 模組。

若要使用 PowerShellGet 安裝 MSCommerce PowerShell 模組,請執行下列命令:

Install-Module -Name MSCommerce

將 MSCommerce 匯入 PowerShell 工作階段

在您的 Windows 10 裝置上安裝模組之後,您會將它匯入到您啟動的每個 PowerShell 工作階段。 若要將它匯入 PowerShell 工作階段,請執行下列命令:

Import-Module -Name MSCommerce

使用您的認證連線到 MSCommerce

若要使用您的認證連線到 PowerShell 模組,請執行下列命令。

Connect-MSCommerce

此命令會將目前的PowerShell會話連線至 Microsoft Entra 租使用者。 命令會提示您輸入要連線之租用戶的使用者名稱和密碼。 如果您的認證已啟用多重要素驗證,您可以使用互動式選項來登入。

檢視 AllowSelfServicePurchase 的詳細數據

若要檢視 AllowSelfServicePurchase 參數值和默認狀態的描述,請根據您的組織執行下列命令:

Get-MSCommercePolicy -PolicyId AllowSelfServicePurchase

檢視自助式購買產品及其狀態的清單

若要檢視所有可用自助式購買產品的清單和每個產品的狀態,請執行下列命令:

Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase

下表列出可用的產品及其 ProductId。 它也會指出哪些產品有可用的試用版,而且不需要付款方式。 如果適用,所有其他試用版都需要付款方式。 對於已啟用試用版但未啟用付款方式的產品,您可以啟用試用版,同時保持停用購買產品的能力。 如需範例命令,請參閱檢視或設定 AllowSelfServicePurchase 的狀態。

產品 ProductId 是否啟用未使用付款方式的試用版?
Clipchamp Premium CFQ7TTC0N8SS
每位使用者的Power Apps* CFQ7TTC0LH2H
每位使用者的Power Automate* CFQ7TTC0LH3L
Power Automate RPA* CFQ7TTC0LSGZ
Power BI Premium (獨立) * CFQ7TTC0H6RP
Power BI Pro* CFQ7TTC0H9MP
Project 方案 1* CFQ7TTC0HDB1
Project 方案 3* CFQ7TTC0HDB0
Teams Exploratory CFQ7TTC0J1FV
Teams 進階版 簡介定價 CFQ7TTC0RM8K
Visio 方案 1* CFQ7TTC0HD33
Visio 方案 2* CFQ7TTC0HD32
僅 Viva Goals (自助式試用) CFQ7TTC0PW0V
Windows 365 企業版 CFQ7TTC0HHS9
Windows 365 商務版 CFQ7TTC0J203
Windows 365 商務版 與 Windows Hybrid Benefit CFQ7TTC0HX99
Microsoft 365 F3 CFQ7TTC0LH05
Microsoft Purview Discovery CFQ7TTC0N8SL

*這些標識碼已變更。 如果您先前使用舊標識碼封鎖產品,則會使用新的標識元自動封鎖產品。 不需要其他工作。

檢視自助式購買「第三方供應專案類型」及其狀態的清單

若要檢視所有可用的自助式購買第三方供應項目類型和每個供應專案的狀態清單,請執行下列命令:

Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase -Scope OfferType

下表列出可用的第三方供應項目類型。 您可以針對自助式購買啟用或停用這些供應項目類型。

供應項目類型 識別碼
軟體即服務 SaaS
Power BI 視覺效果 POWERBIVISUALS
Dynamics 365 Dataverse Apps DYNAMICSCE
Dynamics 365 Business Central DYNAMICSBC

檢視或設定 AllowSelfServicePurchase 的狀態

您可以設定 AllowSelfServicePurchaseValue 參數,以允許或防止使用者進行自助式購買。 您也可以使用 OnlyTrialsWithoutPaymentMethod 值,讓使用者試用不需要付款的產品試用。 請參閱上述產品清單,以查看哪些產品已啟用這些試用版。 如果已啟用 AllowSelfServicePurchase ,使用者只能在試用版結束后購買產品。

注意事項

變更 AllowSelfServicePurchaseOnlyTrialsWithoutPaymentMethod 的值只會影響從該時間點起針對指定產品進行的試用或購買。 指定產品的現有試用版或購買專案不會受到影響。

下表描述 Value 參數的設定。

設定 影響
Enabled 用戶可以進行自助式購買,並取得產品的試用版。
OnlyTrialsWithoutPaymentMethod 用戶無法進行自助式購買,但可以針對不需要他們新增付款方式的產品取得免費試用版。 試用版到期之後,使用者就無法購買產品的付費版本。
已停用 用戶無法進行自助式購買或取得產品的試用版。

若要取得特定產品的原則設定,請執行下列命令:

Get-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId CFQ7TTC0KP0N

若要啟用特定產品的原則設定,請執行下列命令:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId CFQ7TTC0KP0N -Value "Enabled"

若要停用特定產品的原則設定,請執行下列命令:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId CFQ7TTC0KP0N -Value "Disabled"

若要允許使用者在沒有付款方式的情況下試用特定產品,請執行下列命令:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId CFQ7TTC0KP0N -Value "OnlyTrialsWithoutPaymentMethod" 

若要取得特定第三方供應專案類型的原則設定,請執行下列命令:

Get-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -OfferType <ID>

若要啟用特定第三方供應專案類型的原則設定,請執行下列命令:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -OfferType <ID> -Value "Enabled"

若要停用特定第三方供應專案類型的原則設定,請執行下列命令:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -OfferType <ID> -Value "Disabled"

停用 AllowSelfServicePurchase 的範例腳本

下列範例會逐步引導您匯入 MSCommerce 模組、使用您的帳戶登入、取得每位使用者的 Power Automate ProductId ,然後停用該產品的 AllowSelfServicePurchase

Import-Module -Name MSCommerce
Connect-MSCommerce #sign-in with your global or billing administrator account when prompted
$product = Get-MSCommerceProductPolicies -PolicyId AllowSelfServicePurchase | where {$_.ProductName -match 'Power Automate per user'}
Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId $product.ProductID -Value "Disabled"

如果產品有多個值,您可以針對每個值個別執行 命令,如下列範例所示:

Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId $product[0].ProductID -Value "Disabled"
Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -ProductId $product[1].ProductID -Value "Disabled"
Update-MSCommerceProductPolicy -PolicyId AllowSelfServicePurchase -OfferType SaaS -Value "Disabled"

疑難排解

問題

您會看到下列錯誤訊息:

HandleError:無法擷取 PolicyId 為 'AllowSelfServicePurchase'、ErrorMessage 的原則 - 基礎聯機已關閉:傳送時發生非預期的錯誤。

這可能是因為舊版的傳輸層安全性 (TLS) 。 當您連線到此服務時,必須使用 TLS 1.2 或更新版本

解決方案

升級至 TLS 1.2。 下列語法會更新 ServicePointManager 安全性通訊協定以允許 TLS1.2:

[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12

若要深入瞭解,請 參閱如何啟用 TLS 1.2

管理自助式購買 (管理員) (文章)
自助式購買常見問題 (文章)