简体   繁体   中英

Powershell Check MIME exists in IIS

I've got the following command to add a MIME type to IIS using PowerShell

add-webconfigurationproperty //staticContent -name collection -value @{fileExtension='.xpa'; mimeType='application/octet-stream'} 

How can I check if the MIME type exists first before invoking add-webconfigurationproperty ?

You can check with the following:

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

You can also check for the existence of a 'property' using this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM