Powershell Script through SCCM 1902

DukeHazord 1 Reputation point
2021-01-28T13:05:02.84+00:00

Hi,

I have a question regarding executing custom PS Scripts via SCCM. I am trying run a PowerShell script via task sequence by invoking through command line.

%windir%\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy Bypass -File C:\users\public\PersonalTemplates.ps1 -CurrentUser

I am trying to amend an entry in HKCU via script. The task sequence suggests it ended successfully. The script returns with code 0 but it doesn't modify/amend the value in the registry. Instead, I get the following error in the smsts.log:

RegQueryValueExW is unsuccessful for Software\Microsoft\SMS\Task Sequence, SMSTSEndProgram TSManager 13936 (0x3670)

GetTsRegValue() is unsuccessful. 0x80070002. TSManager 13936 (0x3670)

I have even tried the sysnative path suggestion but it fails to find that path (as I believe it doesn't exist) All our clients machines are 64 bit Windows 10 systems

When the script is run manually on a machine, it works absolutely fine.

Please advise what am I doing wrong

Regards.

Microsoft Security Intune Configuration Manager Other
{count} votes

2 answers

Sort by: Most helpful
  1. Youssef Saad 3,416 Reputation points
    2021-01-31T20:08:52.623+00:00

    Hi @DukeHazord ,

    Have you tried create a package with the script & command line and add it on your task sequence? Make sure you deploy the script in the user context.

    Regards,


    Youssef Saad | New blog: https://youssef-saad.blogspot.com
    Please remember to ** “Accept answer” ** or upvote for useful answers, thank you!


  2. Gary Blok 1,756 Reputation points
    2021-02-02T06:35:09.973+00:00

    This biggest issue is that CM runs in System Context, so HKCU isn't really a thing when running a process via CM.

    Now there are some things in CM that you can do to make things run in the logged on user's context, but not in a Task Sequence. ServiceUI.exe was a way to get around this limitation to display things to the user, but that won't help in this situation.

    If you're trying to set a registry value for users, I'd suggest using a configuration item and having it run in the user's context, which will have rights to the user's registry hive.
    62739-image.png

    The best way to deal with USER registry items IMO, is group policy.

    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.