Task sequence run PowerShell script with alternate credentials

ritmo2k 806 Reputation points
2021-01-03T03:42:46.7+00:00

I have a task sequence item that runs a PowerShell script in the later stage after the Config Manager client is installed. When I run that script using an alternate context for a domain user (with local admin rights), it fails to load the com object required to access task sequence variables.

$tsEnv = New-Object -ComObject Microsoft.SMS.TSEnvironment -ErrorAction Stop

This throws the following:

New-Object : Retrieving the COM class factory for component with CLSID {00000000-0000-0000-0000-000000000000} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

Anyone have an idea how to make that work, or is the instance only available to the local system context?

Microsoft Configuration Manager Deployment
Microsoft Configuration Manager Deployment
Microsoft Configuration Manager: An integrated solution for for managing large groups of personal computers and servers.Deployment: The process of delivering, assembling, and maintaining a particular version of a software system at a site.
990 questions
Microsoft Configuration Manager
0 comments No comments
{count} votes

Accepted answer
  1. Gary Blok 1,741 Reputation points
    2021-01-03T04:37:09.257+00:00

    How I got around this was to write the Variables to the registry in a place the user account had access to. You could also output them to a file and then read them back in your other script.

    You'll have to to do something creative to pull that information, as like you've discovered, you can't access the TS Environment when using "run as".

    OR... You can pass them in to the script using parameters.

    https://docs.recastsoftware.com/ConfigMgr-Docs/TaskSequence/SCCM_TaskSequence_Step_RunPowerShellScript.html

    Check out the parameters section, you could pass them in like -OSDComputerName %OSDCOMPUTERNAME% -SMSTSPackageID %SMSTSPackageID

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. ritmo2k 806 Reputation points
    2021-01-03T16:43:18.757+00:00

    Thank you for the detailed response.

    0 comments No comments

Your answer

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