Run a Powershell script from inside the toolkit script

Hello Everyone.

I have some code that I have tried to incorporate into the Powershell script of the Toolkit that isn’t working from that script. It works fine in an independent script, but won’t work from the toolkit for some reason. Basically what I’m trying to do is set the default shell launcher .exe and seperate shell for Admins. Code below:

$COMPUTER = “localhost”
$NAMESPACE = “root\standardcimv2\embedded”
$ShellLauncherClass = [wmiclass]"\$COMPUTER${NAMESPACE}:WESL_UserSetting"
$Admins_SID = “S-1-5-32-544”
$ShellLauncherClass.SetDefaultShell(’"C:\Program Files (x86)\Yadda yadda yadda /config “c:\Program Files (x86)\Yada yada yada”’,0)
$ShellLauncherClass.SetCustomShell($Admins_SID, “explorer.exe”)

Any ideas on how to get this to work IN the toolkit would be great, barring that, any ideas on how to run an independent script from the toolkit would be helpful as well.

Thank you.

Brian J.

What is the error message in the PSADT log file?

CAVEAT: I have not fully read the whole article at

There is no error in the PSADT toolkit log. To date, I have been wrapping up the language in the website you linked into a .exe and calling it that way. We were trying to get away from that and just incorporate the language into the PSADT script, but it’s giving me fits.


According to this, some of these lines return a code which might help for troubleshooting.

Here’s your code above with additional logging added:

Try {
	$COMPUTER = "localhost"
	$NAMESPACE = "root\standardcimv2\embedded"
	$ShellLauncherClass = [wmiclass]"\$COMPUTER${NAMESPACE}:WESL_UserSetting"
	$Admins_SID = "S-1-5-32-544"
	$ResultDef = $ShellLauncherClass.SetDefaultShell('"C:\Program Files (x86)\Yadda yadda yadda /config "c:\Program Files (x86)\Yada yada yada"',0)
	Write-log "Result for .SetDefaultShell = [$($ResultDef | Out-String)]"
	$ResultCust = $ShellLauncherClass.SetCustomShell($Admins_SID, "explorer.exe")
	Write-log "Result for .SetCustomShell = [$($ResultCust | Out-String)]"
} Catch {
	[String]$myErrorMessage = @{'Message:' = "$($_.Exception.Message)";'ScriptStackTrace:'="$($_.ScriptStackTrace)";'InnerException:'="$($_.Exception.InnerException)"} `
        | Format-Table -AutoSize -Wrap -HideTableHeaders | Out-String
	Write-log "ERROR with WESL_UserSetting: [$myErrorMessage]" -Severity 3

I don’t know enough about this SetDefaultShell stuff to really help :pensive:
I think we’re missing a line or 2.