How can I find the potential source environment variable for a partial path in PowerShell?
问题 I want to write a function that converts regular path to path that includes environment variables: For example: C:\Windows\SomePath convert to: %Windir%\SomePath How would I do that and is this possible? Here is what I'm trying to do, but problem is, I need to check the string for all possible variables, is there some more automatic way? such that -replace operator wont be needed function Format-Path { param ( [parameter(Mandatory = $true)] [string] $FilePath ) if (![System.String]: