Powershell 检查 IIS 中是否存在 MIME

Powershell Check MIME exists in IIS

我有以下命令使用 PowerShell

MIME 类型添加到 IIS
add-webconfigurationproperty //staticContent -name collection -value @{fileExtension='.xpa'; mimeType='application/octet-stream'} 

如何在调用之前先检查 MIME 类型是否存在add-webconfigurationproperty

您可以通过以下方式查看:

if( !((Get-WebConfiguration //staticcontent).collection | ? {$_.fileextension -eq '.xpa'}) ) {
  #do something
}

您还可以使用以下方法检查 'property' 是否存在:

if (!(Get-WebConfigurationProperty //staticContent -Name collection[fileExtension=".xpa"])) 
{ 
    Write-Host ".xpa doesn't exist"
}