Packages deployed as System context via SCCM

Prabhjot Singh 255 Reputation points
2024-08-26T13:27:13.8766667+00:00

Hi Team,

I hope you all are doing well. actually, I got stuck in a scenario where we have to deploy packages (Script package) as system context into devices via SCCM. Currently, what we are trying to do is, we need to deploy Script package as system context and needs to run inner part of script in user context.

Is there a way to trigger inner part of script as user context when deployed into devices as system context.

For reference, our current command line - %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy ByPass -file

Do we need add any other parameter for triggering the inner part of script as user context when deploying as system context.

Do help to get through this. Thanks!

Microsoft Security | Intune | Configuration Manager | Deployment
Microsoft Security | Intune | Configuration Manager | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. XinGuo-MSFT 22,246 Reputation points
    2024-08-27T08:44:54.25+00:00

    Hi,

    You can use Invoke-Command to run a script block as a specific user. This requires the user credentials:

    Store User Credentials:

    $username = "DOMAIN\User"
    $password = ConvertTo-SecureString "password" -AsPlainText -Force
    $credential = New-Object System.Management.Automation.PSCredential($username, $password)
    
    

    Invoke Command as User:

    Invoke-Command -ScriptBlock { & "C:\Path\To\YourScript.ps1" } -Credential $credential
    
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.