你可以透過 Microsoft Defender for Cloud PowerShell 模組,以程式化方式保護你的 Azure 工作負載。 使用PowerShell可讓您自動化工作,並避免手動工作固有的人為錯誤。 這在涉及數十個訂用帳戶的大規模部署中特別有用,其中包含數百甚至數千個資源,這一切必須一開始就受到保護。
使用 PowerShell 導入 Microsoft Defender for Cloud 可讓你程式化自動化 Azure 資源的導入與管理,並新增必要的安全控管。
本文提供一個範例 PowerShell 腳本,可修改並在你的環境中使用,以在你的訂閱中推廣 Defender for Cloud。
在此範例中,我們將啟用 ID: <Subscription ID> 的訂閱Defender for Cloud,並套用推薦的設定,透過啟用 Microsoft Defender for Cloud 增強的安全功能,提供進階的威脅防護與偵測功能,以提供高層級的保護:
啟用
Microsoft Defender for Cloud 的加強安全性<>。 指派 Defender for Cloud 的 預設安全政策。
先決條件
以下步驟應在執行 Defender for Cloud 指令前完成:
以系統管理員身分執行 PowerShell。
在 PowerShell 中執行下列命令:
Set-ExecutionPolicy -ExecutionPolicy AllSignedInstall-Module -Name Az.Security -Force
使用 PowerShell 導入 Microsoft Defender for Cloud
註冊您的 Defender for Cloud 資源提供者訂閱:
Set-AzContext -Subscription "<Subscription ID>"Register-AzResourceProvider -ProviderNamespace 'Microsoft.Security'可選:設定訂閱的覆蓋等級(開啟或關閉 Microsoft Defender for Cloud 的強化安全功能)。 如果未定義,這些功能會關閉:
Set-AzContext -Subscription "<Subscription ID>"Set-AzSecurityPricing -Name "VirtualMachines" -PricingTier "Standard"可選:強烈建議您定義您所加入訂閱的資安聯絡方式,這些資訊將作為Defender for Cloud產生的警示與通知接收者:
Set-AzSecurityContact -Name "default1" -Email "CISO@my-org.com" -AlertAdmin -NotifyOnAlert指派預設的適用於雲端的 Defender 原則倡議:
Register-AzResourceProvider -ProviderNamespace 'Microsoft.PolicyInsights'$Policy = Get-AzPolicySetDefinition | where {$_.Properties.displayName -EQ 'Microsoft cloud security benchmark'} New-AzPolicyAssignment -Name 'Microsoft cloud security benchmark' -PolicySetDefinition $Policy -Scope '/subscriptions/$($Subscription.Id)'
你已經成功讓 Microsoft Defender for Cloud 搭配 PowerShell 上線。
您現在可以使用這些 PowerShell Cmdlet 搭配自動化腳本,以程式設計方式反覆運算訂用帳戶和資源。 這樣可節省時間並降低人為錯誤的可能性。 你可以用這個範例腳本作為參考。
另請參閱
想了解更多如何使用 PowerShell 自動化導入 Defender for Cloud,請參閱以下文章:
想了解更多關於 Defender for Cloud 的資訊,請參閱以下文章:
- 在 Microsoft Defender for Cloud 設定安全政策。 學習如何為你的 Azure 訂閱與資源群組設定安全政策。
- 管理並回應Microsoft Defender for Cloud的安全警示。 了解如何管理和回應安全性警示。