I am trying to change the Physical Path for each Virtual Directory under each Application and each Site in IIS through PowerShell.
For example, this command changes Physical Path (/) for one of the Virtual Directories (/) under Applications (MSMQ) under Site (Default Web Site).
Set-WebConfigurationProperty -pspath 'MACHINE/WEBROOT/APPHOST' -filter "system.applicationHost/sites/site[@name='Default Web Site']/application[@path='/MSMQ']/virtualDirectory[@path='/']" -name "physicalPath" -value "F:\inetpub\wwwroot\msmq"
Similarly, I want to change for all applications under all sites.
Referred to following links but, no luck.
Update:
I got it working with following code. Can this be done in a cleaner/optimized way?
C:\windows\system32\inetsrv\appcmd.exe list vdirs | ForEach-Object {
$vDir = $_|%{$_.split('"')[1]}
$_ -match ".?\((.*?)\).*" | Out-Null
$phyPath = $matches[1].Replace("physicalPath:","")
Write-Output "VDIR is $vDir and Physical Path is $phyPath"
$newPath=$phyPath.Replace("C:","F:")
Write-Output "New Physical Path is $newPath"
C:\windows\system32\inetsrv\appcmd.exe set vdir $vDir -physicalPath:$newPath
}
Comments
Post a Comment