この記事では、次のようなさまざまなAzure サービスに対して Microsoft マルウェア対策を有効にして構成するための PowerShell コード サンプルを提供します。
- Azureリソースマネージャー仮想マシン
- Azure Service Fabric クラスター
- 延長サポートを使用したAzure Cloud Services
- Azure Arc対応サーバー
これらのサンプルを使用して、Azure環境全体に Microsoft マルウェア対策拡張機能を展開して構成できます。
Azure Resource Manager VM に Microsoft Antimalware を展開する
注
このコード サンプルを実行する前に、変数のコメントを解除し、適切な値を指定する必要があります。
Warnung
この拡張機能を展開または更新すると、除外を含む既存の Microsoft Defender ウイルス対策設定が置き換えられます。 設定を保持するには、拡張機能の構成で設定を指定します。 詳細については、「 既定およびカスタムマルウェア対策の構成」を参照してください。
# Script to add Microsoft Antimalware extension to Azure Resource Manager VMs
# Specify your subscription ID
$subscriptionId= " SUBSCRIPTION ID HERE "
# specify location, resource group, and VM for the extension
$location = " LOCATION HERE " # eg., “Southeast Asia” or “Central US”
$resourceGroupName = " RESOURCE GROUP NAME HERE "
$vmName = " VM NAME HERE "
# Enable Antimalware with default policies
$settingString = ‘{"AntimalwareEnabled": true}’;
# Enable Antimalware with custom policies
# $settingString = ‘{
# "AntimalwareEnabled": true,
# "RealtimeProtectionEnabled": true,
# "ScheduledScanSettings": {
# "isEnabled": true,
# "day": 0,
# "time": 120,
# "scanType": "Quick"
# },
# "Exclusions": {
# "Extensions": ".ext1,.ext2",
# "Paths":"",
# "Processes":"sampl1e1.exe, sample2.exe"
# },
# "SignatureUpdates": {
# "FileSharesSources": “”,
# "FallbackOrder”: “”,
# "ScheduleDay": 0,
# "UpdateInterval": 0,
# },
# "CloudProtection": true
#
# }’;
# Login to your Azure Resource Manager Account and select the Subscription to use
Login-AzureRmAccount
Select-AzureRmSubscription -SubscriptionId $subscriptionId
# retrieve the most recent version number of the extension
$allVersions= (Get-AzureRmVMExtensionImage -Location $location -PublisherName “Microsoft.Azure.Security” -Type “IaaSAntimalware”).Version
$versionString = $allVersions[($allVersions.count)-1].Split(“.”)[0] + “.” + $allVersions[($allVersions.count)-1].Split(“.”)[1]
# set the extension using prepared values
# ****—-Use this script till cmdlets address the -SettingsString format issue we observed ****—-
Set-AzureRmVMExtension -ResourceGroupName $resourceGroupName -Location $location -VMName $vmName -Name "IaaSAntimalware" -Publisher “Microsoft.Azure.Security” -ExtensionType “IaaSAntimalware” -TypeHandlerVersion $versionString -SettingString $settingString
Azure Service Fabric クラスターに Microsoft マルウェア対策を追加する
Azure Service Fabricでは、Azure仮想マシン スケール セットを使用して Service Fabric クラスターを作成します。 現在、Service Fabric クラスターの作成に使用される仮想マシン スケール セット テンプレートは、マルウェア対策拡張機能では有効になっていません。 そのため、スケール セットでマルウェア対策を個別に有効にする必要があります。 スケール セットで有効にすると、仮想マシン スケール セットの下に作成されたすべてのノードが継承され、拡張機能が自動的に取得されます。
次のコード サンプルは、AzureRmVmss PowerShell コマンドレットを使用して IaaS マルウェア対策拡張機能を有効にする方法を示しています。
注
このコード サンプルを実行する前に、変数のコメントを解除し、適切な値を指定する必要があります。
Warnung
この拡張機能を展開または更新すると、除外を含む既存の Microsoft Defender ウイルス対策設定が置き換えられます。 設定を保持するには、拡張機能の構成で設定を指定します。 詳細については、「 既定およびカスタムマルウェア対策の構成」を参照してください。
# Script to add Microsoft Antimalware extension to VM Scale Set(VMSS) and Service Fabric Cluster(in turn it used VMSS)
# Login to your Azure Resource Manager Account and select the Subscription to use
Login-AzureRmAccount
# Specify your subscription ID
$subscriptionId="SUBSCRIPTION ID HERE"
Select-AzureRmSubscription -SubscriptionId $subscriptionId
# Specify location, resource group, and VM Scaleset for the extension
$location = "LOCATION HERE" # eg., “West US or Southeast Asia” or “Central US”
$resourceGroupName = "RESOURCE GROUP NAME HERE"
$vmScaleSetName = "YOUR VM SCALE SET NAME"
# Configuration.JSON configuration file can be customized as per MSDN documentation: https://msdn.microsoft.com/en-us/library/dn771716.aspx
$settingString = ‘{"AntimalwareEnabled": true}’;
# Enable Antimalware with custom policies
# $settingString = ‘{
# "AntimalwareEnabled": true,
# "RealtimeProtectionEnabled": true,
# "ScheduledScanSettings": {
# "isEnabled": true,
# "day": 0,
# "time": 120,
# "scanType": "Quick"
# },
# "Exclusions": {
# "Extensions": ".ext1,.ext2",
# "Paths":"",
# "Processes":"sampl1e1.exe, sample2.exe"
# } ,
# "SignatureUpdates": {
# "FileSharesSources": “”,
# "FallbackOrder”: “”,
# "ScheduleDay": 0,
# "UpdateInterval": 0,
# },
# "CloudProtection": true
# }’;
# retrieve the most recent version number of the extension
$allVersions= (Get-AzureRmVMExtensionImage -Location $location -PublisherName “Microsoft.Azure.Security” -Type “IaaSAntimalware”).Version
$versionString = $allVersions[($allVersions.count)-1].Split(“.”)[0] + “.” + $allVersions[($allVersions.count)-1].Split(“.”)[1]
$VMSS = Get-AzureRmVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmScaleSetName
Add-AzureRmVmssExtension -VirtualMachineScaleSet $VMSS -Name “IaaSAntimalware” -Publisher “Microsoft.Azure.Security” -Type “IaaSAntimalware” -TypeHandlerVersion $versionString
Update-AzureRmVmss -ResourceGroupName $resourceGroupName -Name $vmScaleSetName -VirtualMachineScaleSet $VMSS
延長サポートを使用してクラウド サービスAzureに Microsoft マルウェア対策を追加する
次のコード サンプルは、PowerShell コマンドレットを使用して拡張サポート (CS-ES) を使用して、クラウド サービスをAzureするように Microsoft マルウェア対策を追加または構成する方法を示しています。
注
このコード サンプルを実行する前に、変数のコメントを解除し、適切な値を指定する必要があります。
Warnung
この拡張機能を展開または更新すると、除外を含む既存の Microsoft Defender ウイルス対策設定が置き換えられます。 設定を保持するには、拡張機能の構成で設定を指定します。 詳細については、「 既定およびカスタムマルウェア対策の構成」を参照してください。
# Create Antimalware extension object, where file is the AntimalwareSettings
$xmlconfig = [IO.File]::ReadAllText("C:\path\to\file.xml")
$extension = New-AzCloudServiceExtensionObject -Name "AntimalwareExtension" -Type "PaaSAntimalware" -Publisher "Microsoft.Azure.Security" -Setting $xmlconfig -TypeHandlerVersion "1.5" -AutoUpgradeMinorVersion $true
# Get existing Cloud Service
$cloudService = Get-AzCloudService -ResourceGroup "ContosOrg" -CloudServiceName "ContosoCS"
# Add Antimalware extension to existing Cloud Service extension object
$cloudService.ExtensionProfile.Extension = $cloudService.ExtensionProfile.Extension + $extension
# Update Cloud Service
$cloudService | Update-AzCloudService
プライベート構成 XML ファイルの例を次に示します
<?xml version="1.0" encoding="utf-8"?>
<AntimalwareConfig
xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<AntimalwareEnabled>true</AntimalwareEnabled>
<RealtimeProtectionEnabled>true</RealtimeProtectionEnabled>
<ScheduledScanSettings isEnabled="true" day="1" time="120" scanType="Full" />
<Exclusions>
<Extensions>
<Extension>.ext1</Extension>
<Extension>.ext2</Extension>
</Extensions>
<Paths>
<Path>c:\excluded-path-1</Path>
<Path>c:\excluded-path-2</Path>
</Paths>
<Processes>
<Process>excludedproc1.exe</Process>
<Process>excludedproc2.exe</Process>
</Processes>
</Exclusions>
</AntimalwareConfig>
Azure Arc対応サーバーの Microsoft マルウェア対策を追加する
次のコード サンプルは、PowerShell コマンドレットを使用して、Azure Arc対応サーバーに Microsoft マルウェア対策を追加する方法を示しています。
注
このコード サンプルを実行する前に、変数のコメントを解除し、適切な値を指定する必要があります。
#Before using Azure PowerShell to manage VM extensions on your hybrid server managed by Azure Arc-enabled servers, you need to install the Az.ConnectedMachine module. Run the following command on your Azure Arc-enabled server:
#If you have Az.ConnectedMachine installed, please make sure the version is at least 0.4.0
install-module -Name Az.ConnectedMachine
Import-Module -name Az.ConnectedMachine
# specify location, resource group, and VM for the extension
$subscriptionid =" SUBSCRIPTION ID HERE "
$location = " LOCATION HERE " # eg., “Southeast Asia” or “Central US”
$resourceGroupName = " RESOURCE GROUP NAME HERE "
$machineName = "MACHINE NAME HERE "
# Enable Antimalware with default policies
$setting = @{"AntimalwareEnabled"=$true}
# Enable Antimalware with custom policies
$setting2 = @{
"AntimalwareEnabled"=$true;
"RealtimeProtectionEnabled"=$true;
"ScheduledScanSettings"= @{
"isEnabled"=$true;
"day"=0;
"time"=120;
"scanType"="Quick"
};
"Exclusions"= @{
"Extensions"=".ext1, .ext2";
"Paths"="";
"Processes"="sampl1e1.exe, sample2.exe"
};
"SignatureUpdates"= @{
"FileSharesSources"=“”;
"FallbackOrder”=“”;
"ScheduleDay"=0;
"UpdateInterval"=0;
};
"CloudProtection"=$true
}
# Will be prompted to login
Connect-AzAccount
# Enable Antimalware with the policies
New-AzConnectedMachineExtension -Name "IaaSAntimalware" -ResourceGroupName $resourceGroupName -MachineName $machineName -Location $location -SubscriptionId $subscriptionid -Publisher “Microsoft.Azure.Security” -Settings $setting -ExtensionType “IaaSAntimalware”