Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,9 @@ private PSDataCollection<PSObject> InvokeScript(Command cmdToRun, RunspaceCreate
{
Debug.Assert(cmdToRun != null, "cmdToRun shouldn't be null");

cmdToRun.CommandOrigin = CommandOrigin.Internal;
// Don't invoke initialization script as trusted (CommandOrigin == Internal) if the system is in lock down mode.
cmdToRun.CommandOrigin = (SystemPolicy.GetSystemLockdownPolicy() == SystemEnforcementMode.Enforce) ? CommandOrigin.Runspace : CommandOrigin.Internal;

cmdToRun.MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
PowerShell powershell = PowerShell.Create();
powershell.AddCommand(cmdToRun).AddCommand("out-default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ try
}
}

Describe "Start-Job initialization script should work in system lock down" -Tags 'Feature','RequireAdminOnWindows' {

It "Verifies that Start-Job initialization script runs successfully in system lock down" {

try
{
Invoke-LanguageModeTestingSupportCmdlet -SetLockdownMode
$ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"

$job = Start-Job -InitializationScript { function Hello { "Hello" } } -ScriptBlock { Hello }
$result = $job | Wait-Job | Receive-Job
}
finally
{
Invoke-LanguageModeTestingSupportCmdlet -RevertLockdownMode -EnableFullLanguageMode
}

$result | Should -BeExactly "Hello"
$job | Remove-Job
}
}

# End Describe blocks
}
finally
Expand Down