I've found the solution after much testing, see updates below

我在Azure中有很多(很多)PaaS服务,我需要全面安装Microsoft反恶意软件 .

"Thats easy!"我听到你说,“只需调用Set-AzureServiceAntimalwareExtension”,并且's what I' m当前正在执行(使用Set-AzureServiceDiagnosticsExtension启用诊断后),并且运行更新版本的SDK并且诊断已经转移到服务中了's very tedious as it has to update the whole service (twice if it'! ) .

理想情况下,我想将其捆绑到服务部署中,因为我们做了很多事情,并且搞乱部署诊断和反恶意软件只会让水变得混乱 . 据我所知,New-AzureDeployment / Set-AzureDeployment CmdLet上有一个参数,允许您传入ExtensionConfiguration,实际上它是一个配置数组!

这是否意味着我可以将诊断和反恶意软件设置作为软件包部署的一部分传递?这听起来很疯狂,我喜欢它,但我可以让它工作吗?不是现在...

目前,这是我需要它的每个服务的方法:

Set-AzureServiceDiagnosticsExtension –ServiceName $serviceName -DiagnosticsConfigurationPath $diagnosticConfig -StorageContext $storageContext 
Set-AzureServiceAntimalwareExtension -ServiceName $serviceName -AntimalwareConfiguration $malwareConfig -StorageContext $storageContext

但是,当我们已经部署/升级部署时,简单地执行此操作将会容易得多,例如:

$extensionConfiguration = New-AzureServiceExtensionConfig ... ?
Set-AzureDeployment -ServiceName $serviceName ... -ExtensionConfiguration $extensionConfiguration

现在看起来我们越来越近了,但是New-AzureServiceExtensionConfig需要一堆参数,ExtensionName和ProviderNamespace应该可以解决(简单地看一下当前方法的内容),但是什么进入PublicConfiguration并且PrivateConfiguration?我有一个用于诊断的.wadcfgx,以及反恶意软件配置的XML片段,这些是公共配置吗?我可以看到现有服务的情况如此,但需要PrivateConfiguration .


Update 1: 我发现如何在程序包部署中添加诊断程序,我们获取密钥,创建存储上下文,并使用我们的.wadcfgx(其中没有定义私有配置/ StorageAccount)传递它:

$keys = Get-AzureStorageKey -StorageAccountName $storageAccount
$storageContext = New-AzureStorageContext –StorageAccountName $storageAccount –StorageAccountKey $keys.Primary
$serviceExtensionDiags = New-AzureServiceDiagnosticsExtensionConfig -StorageContext $storageContext -DiagnosticsConfigurationPath "C:\path\to\diagnostics.wadcfgx"

然后将上面创建的$ serviceExtensionDiags传递给包部署步骤,如下所示:

Set-AzureDeployment -Configuration $configPath -Package $packagePath -Upgrade -Label $label -ServiceName $serviceName -Slot "Production" -ExtensionConfiguration $serviceExtensionDiags

Update 2: 最后一块拼图,将Microsoft Antimalware作为部署的一部分安装......我使用了几个这里的字符串,但是YMMV:

$publicConfig = @"
<?xml version="1.0" encoding="utf-8"?>
<AntimalwareConfig>
  <AntimalwareEnabled>true</AntimalwareEnabled>
  <RealtimeProtectionEnabled>true</RealtimeProtectionEnabled>
  <ScheduledScanSettings isEnabled="true" day="1" time="60" scanType="Full" />
  <Exclusions>
    <Extensions>
      <Extension></Extension>
    </Extensions>
    <Paths>
      <Path></Path>
    </Paths>
    <Processes>
      <Process></Process>
    </Processes>
  </Exclusions>
</AntimalwareConfig>
"@

$privateConfig = @"
<?xml version="1.0" encoding="utf-8"?>
<PrivateConfig>
  <StorageAccountName>xxx</StorageAccountName>
  <StorageKey>yyy</StorageKey>
</PrivateConfig>
"@

$serviceExtensionMalware = New-AzureServiceExtensionConfig -ExtensionName "PaaSAntimalware" -ProviderNamespace "Microsoft.Azure.Security" -PublicConfiguration $publicConfig -PrivateConfiguration $privateConfig -Version 1.0

最后,我们将Malware配置添加到我们的更新部署中:

Set-AzureDeployment -Configuration $configPath -Package $packagePath -Upgrade -Label $label -ServiceName $serviceName -Slot "Production" -ExtensionConfiguration @($serviceExtensionDiags, $serviceExtensionMalware)

我们完成了!