When I try to get the file using the following path - it fails:
$path = Get-ItemProperty -Path "%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll"
or
$moduleVersion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll").FileVersion
is there a workaround for this in powershell
?
When I specify the "full path" then it works fine, but I am not actually the one in control of what the value is. So I would expect the path to be resolved automatically as when you paste it directly in Explorer.. but it's not happening.
Get-ItemProperty : Cannot find path 'C:\Users\xxxx\Documents\yyyy\%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll' because it does not exist.
EDIT 1: I have tried to apply the Regex fix but it does not work:
$path = "%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll";
$path = $path -replace "\%(.*?)\%", '$env:$1'
$path2 = Get-ItemProperty -Path "%ProgramFiles%\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll" #does not work
$path3 = Get-ItemProperty -Path "$env:ProgramFiles\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll" #works
$path4 = Get-ItemProperty -Path $path #does not work
Could somebody explain why path3
works but path4
isn't? the values are the same.. Still trying to make this work.