The problem with quotation marks. It works if you, for example. add extra single quotes around your double quotes. It also works with triple double quotes.
Start-Process powershell.exe { $string = """123xAbcxEFG""" $split1,$split2,$split3 = $string.split("""x""") Write-Output $split1 Write-Output $split2 Write-Output $split3 sleep 10 }
How I changed the code to catch an error (without extra double quotes):
$ScriptBlock = { $string = "123xAbcxEFG" $split1,$split2,$split3 = $string.split("x") Write-Output $split1 Write-Output $split2 Write-Output $split3 sleep 10 } Start-Process powershell -argumentlist "-noexit -command $ScriptBlock"
source share