How to create PS alias for EXE with many path para

2019-03-01 07:11发布

问题:

Why such alias doesn't work? In my opinion there is problem with duplicated quotation marks.

New-Alias -Name "chrome" -Value ""C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --user-data-dir="%APPDATA%\Google\Chrome\User Data" --disk-cache-dir="%LocalAppData%\Google\Chrome\User Data""

回答1:

To add to @boxdog's comment, pointing to the alias documentation, you must point your alias to a function if you want parameters.

Consider adding this to your $profile to accomplish your goal:

function Start-Chrome {
    $argList = @(
        "--user-data-dir=`"$Env:AppData\Google\Chrome\User Data`""
        "--disk-cache-dir=`"$Env:LocalAppData\Google\Chrome\User Data`""
    )
    & "${Env:ProgramFiles(x86)}\Google\Chrome\Application\chrome.exe" @argList
}
New-Alias -Name chrome -Value Start-Chrome