I have following Powershell code that make Chrome always opened using default profile when clicked on pinned icon on Taskbar:
$shortcutPath = "$($Env:APPDATA)\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Google Chrome.lnk"
$shell = New-Object -COM WScript.Shell
$shortcut = $shell.CreateShortcut($shortcutPath) ## Open the lnk
$shortcut.TargetPath
if ($shortcut.TargetPath.EndsWith("chrome.exe")) {
$shortcut.TargetPath = """$($shortcut.TargetPath)"" --profile-directory=""Default"""
$shortcut.Save() ## Save
}
When executing it, the if statement throw below error:
Value does not fall within the expected range.
At line:2 char:31
+ $shortcut.TargetPath = """$($shortcut.TargetPath)"" --profile-direc ...
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException
Why I get above error? And how to fix it? Thank!