Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 756
heymega Avatar asked Dec 24 '22 23:12

heymega


2 Answers

You can check with the following:

if( !((Get-WebConfiguration //staticcontent).collection | ? {$_.fileextension -eq '.xpa'}) ) {
  #do something
}
like image 196
arco444 Avatar answered Dec 27 '22 12:12

arco444


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"
}
like image 22
stinkyfriend Avatar answered Dec 27 '22 12:12

stinkyfriend