Share via


Powershell failing in Task Sequence

Question

Thursday, August 3, 2017 1:35 PM

Hi,

I am trying to run two Powershell scripts in my SCCM Windows 10 Task Sequence and the task sequences fail when running the scripts. The TS installs the Windows 10 OS and when it reboots, it begins the next phase which is Setup Operating System.

The first part in this section is to install the SCCM local client, then run my first Powershell Script (Part1).

The way I have configured the script to run is by setting up a empty Package that uses the source folder of the Powershell script. Then, I use the Run Powershell Script option in the Task Sequence and insert my script's name.

Here is the error log from the smsts.log:

Start executing the command line: OSDRunPowerShellScript.exe  TSManager   8/2/2017 4:56:53 PM 1264 (0x04F0)
!!  TSManager   8/2/2017 4:56:53 PM 1264 (0x04F0)
Expand a string: WinPEandFullOS TSManager   8/2/2017 4:56:53 PM 1264 (0x04F0)
Executing command line: OSDRunPowerShellScript.exe  TSManager   8/2/2017 4:56:53 PM 1264 (0x04F0)
[ OSDRunPSScript.exe ]  RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Running powershell script: 'FFRename.ps1'(PkgID: NB200242) with execution policy: 'Bypass'  RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
The execution scope for running the powershell script is specified not to verify the signature of the scripts. This is unsafe and potentially risk running malicious scripts.   RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Sending warning status message  RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
The client GUID must be set in an environment variable. RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
GetClientIDs() failed. 80004005 RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Non fatal error 0x80004005 in sending task sequence execution status message to MP  RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Powershell path: C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe  RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
ResolveSource flags: 0x00000000 RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
SMSTSPersistContent: . The content for package NB200242 will be persisted   RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Found Fullmedia content in drive D:\.   RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Resolved source to 'D:\SMS\PKG\NB200242'    RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Working dir 'D:\SMS\PKG\NB200242'   RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
Executing command line: Run Powershell script   RunPowerShellScript 8/2/2017 4:56:53 PM 3296 (0x0CE0)
The argument 'FFRename.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.   RunPowerShellScript 8/2/2017 4:56:55 PM 3296 (0x0CE0)
Windows PowerShell  RunPowerShellScript 8/2/2017 4:56:56 PM 3296 (0x0CE0)
Copyright (C) 2016 Microsoft Corporation. All rights reserved.  RunPowerShellScript 8/2/2017 4:56:56 PM 3296 (0x0CE0)
RunPowerShellScript 8/2/2017 4:56:56 PM 3296 (0x0CE0)
Process completed with exit code 4294770688 RunPowerShellScript 8/2/2017 4:56:58 PM 3296 (0x0CE0)
Command line returned 4294770688    RunPowerShellScript 8/2/2017 4:56:58 PM 3296 (0x0CE0)
The user tries to release a source directory D:\SMS\PKG\NB200242 that is either already released or we have not connected to it.    RunPowerShellScript 8/2/2017 4:56:58 PM 3296 (0x0CE0)
Process completed with exit code 4294770688 TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
!!  TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Failed to run the action: Run PowerShell Script Part 1. 
Unknown error (Error: FFFD0000; Source: Unknown)    TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Do not send status message in full media case   TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Set a global environment variable _SMSTSLastActionRetCode=-196608   TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Set a global environment variable _SMSTSLastActionSucceeded=false   TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Clear local default environment TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Let the parent group (Setup Operating System) decides whether to continue execution TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
The execution of the group (Setup Operating System) has failed and the execution has been aborted. An action failed.
Operation aborted (Error: 80004004; Source: Windows)    TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Failed to run the last action: Run PowerShell Script Part 1. Execution of task sequence failed.
Unknown error (Error: FFFD0000; Source: Unknown)    TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Do not send status message in full media case   TSManager   8/2/2017 4:56:58 PM 1264 (0x04F0)
Task Sequence Engine failed! Code: enExecutionFail  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
****************************************************************************    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Task sequence execution failed with error code 80004005 TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Cleaning Up.    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Removing Authenticator  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Cleaning up task sequence folder    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Unable to delete file C:\_SMSTaskSequence\TSEnv.dat (0x80070005). Continuing.   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Failed to delete directory 'C:\_SMSTaskSequence'    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
SetNamedSecurityInfo() failed.  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
SetObjectOwner() failed. 0x80070005.    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
RemoveFile() failed for C:\_SMSTaskSequence\TSEnv.dat. 0x80070005.  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
RemoveDirectoryW failed (0x80070091) for C:\_SMSTaskSequence    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Deleting volume ID file C:\_SMSTSVolumeID.7159644d-f741-45d5-ab29-0ad8aa4771ca ...  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Successfully unregistered Task Sequencing Environment COM Interface.    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Executing command line: "C:\ConfigMgr2012\TsProgressUI.exe" /Unregister   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
==========[ TsProgressUI started in process 5400 ]==========    TsProgressUI    8/2/2017 5:11:58 PM 5156 (0x1424)
Unregistering COM classes   TsProgressUI    8/2/2017 5:11:58 PM 5156 (0x1424)
Shutdown complete.  TsProgressUI    8/2/2017 5:11:58 PM 5156 (0x1424)
Process completed with exit code 0  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Successfully unregistered TS Progress UI.   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Failed to delete registry value HKLM\Software\Microsoft\SMS\Task Sequence\Package. Error code 0x80070002    TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Start to cleanup TS policy  TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
End TS policy cleanup   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Start to evaluate TS policy with lock   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Updating settings in \\.\root\ccm\policy\machine\actualconfig   TSManager   8/2/2017 5:11:58 PM 1264 (0x04F0)
Total RequestedConfig policy instance(s) : 485  TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
New/Changed ActualConfig policy instance(s) : 1 TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Raising event:

instance of CCM_PolicyAgent_SettingsEvaluationComplete
{
    DateTime = "20170802221159.546000+000";
    PolicyNamespace = "\\\\.\\root\\ccm\\policy\\machine\\actualconfig";
    ProcessID = 1748;
    ThreadID = 1264;
};
    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Successfully submitted event to the Status Agent.   TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
End TS policy evaluation    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Policy evaluation initiated TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
RegQueryValueExW is unsuccessful for Software\Microsoft\SMS\Task Sequence, SMSTSEndProgram  TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
GetTsRegValue() is unsuccessful. 0x80070002.    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
End program:    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Error Task Sequence Manager failed to execute task sequence. Code 0x80004005    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Sending error status message    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Do not send status message in full media case   TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Finalize logging request ignored from process 1748  TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Waiting for CcmExec service to be fully operational TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
CcmExec service is up and fully operational TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Attempting to release request using {33DB84D0-23A4-4532-BE87-FCC2E847BB23}  TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
ReleaseRequest failed with error code 0x80004005    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Task Sequence Manager could not release active TS request. code 80004005    TSManager   8/2/2017 5:11:59 PM 1264 (0x04F0)
Process completed with exit code 2147500037 TSMBootstrap    8/2/2017 5:11:59 PM 5740 (0x166C)
Exiting with return code 0x80004005 TSMBootstrap    8/2/2017 5:11:59 PM 5740 (0x166C)
Process completed with exit code 2147500037 OSDSetupHook    8/2/2017 5:11:59 PM 4676 (0x1244)
Task sequence completed 0x80004005  OSDSetupHook    8/2/2017 5:11:59 PM 4676 (0x1244)
Restoring original desktop wallpaper.   OSDSetupHook    8/2/2017 5:11:59 PM 4676 (0x1244)
Resume SCCM Client. OSDSetupHook    8/2/2017 5:11:59 PM 4676 (0x1244)
Exiting SetClientProvisioningMode 0x00000000    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Uninstalling Setup Hook OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Removing setup hook from registry.  OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Successfully removed C:\WINDOWS\system32\OSDGINA.DLL    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Could not delete the file C:\WINDOWS\system32\OSDSETUPHOOK.EXE. Error code 5    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Marking the file C:\WINDOWS\system32\OSDSETUPHOOK.EXE for deletion on Reboot    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Successfully removed C:\WINDOWS\system32\OSDSETUPHOOK.EXE   OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Successfully removed C:\WINDOWS\system32\_SMSOSDSetup   OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
::RegQueryValueExW(hSubKey, szReg, NULL, NULL, NULL, &dwSize), HRESULT=80070002 (e:\qfe\nts\sms\framework\tscore\utils.cpp,830) OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
RegQueryValueExW is unsuccessful for Software\Microsoft\SMS\Task Sequence, SMSTSEndProgram  OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
GetTsRegValue() is unsuccessful. 0x80070002.    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
End program:    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Finalizing logging from process 4672    OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)
Successfully finalized logs to SMS client log directory from C:\ConfigMgr2012\Logs  OSDSetupHook    8/2/2017 5:12:01 PM 4676 (0x1244)

Here is the Powershell script:

#Administrator RightsIF (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator"))  { Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit }    #Rename Computer    $originalPCName = 'localhost'   $staticName = 'FF'  $MACAddress = (gwmi Win32_NetworkAdapterConfiguration | ? { $_.Description -match 'Realtek 8821AE' }).MacAddress    $newPCName = $MACAddress.Substring(9,8) -replace ':','-'    $newPCName = $staticName + $newPCName -replace '-',''   Rename-Computer -NewName $newPCName

All replies (15)

Thursday, August 3, 2017 3:30 PM âś…Answered

OK, but are they actually in the package and have those files been transferred to the DP?

In general, copying anything from a network location during a TS or ConfigMgr is bad form. It can work if you set the permissions correctly and name resolution is working, but it defeats part of the main functionality of ConfigMgr and its use of DPs.

If all you want to do is copy files to the systems, use this: https://home.configmgrftw.com/copying-files-to-clients-using-configmgr/

Jason | http://blog.configmgrftw.com | @jasonsandys


Thursday, August 3, 2017 2:13 PM

To give better details, we need to know where in the TS you are running these scripts (think screenshots as a word description where you haven't called out the actual task names and types does not help at all).

The error for the first script is clearly in the log file above though:

"The argument 'FFRename.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' "

Jason | http://blog.configmgrftw.com | @jasonsandys


Thursday, August 3, 2017 3:12 PM

Here is how I have it configured:

I'm not sure how the file parameter does not exist. This is my first attempt at using Powershell in SCCM.


Thursday, August 3, 2017 3:23 PM

Are you sure that file with that name is in the package and that the package has been successfully updated on the DP(s)?

Jason | http://blog.configmgrftw.com | @jasonsandys


Thursday, August 3, 2017 3:24 PM

I have two Powershell script that aren't currently functioning. The first is to rename the computer with 'FF' and then the last six of the MAC address. While it errors, this script does run successfully.

The second script is to copy files from a network path and put them onto the a folder in Windows. This one continually errors saying that it cannot reach the network path. Would there be a better option to do this rather than Powershell? It's just copy of files.


Thursday, August 3, 2017 4:03 PM

Hi Jason,

Perhaps I did not configure the package correctly. As I said, this is my first attempt at this, so thanks for working with me here.

For the package, I configured a SCCM package that doesn't contain any program. Then, I set the source files to a network path as you would normally do in a package.

I agree that if I could do this without network access, I would. I'm following your linked page, however, I get stuck right away on step 1. Create a parent folder in your source file repository. On the page, it appears that the blog is showing the files being posted on the PC itself. This will be done while installing the OS, so it's not like the files can be there right away.

My second powershell script also makes some icons on the public desktop during installation, so I would prefer to fix my Powershell script if possible.


Thursday, August 3, 2017 4:19 PM

> "On the page, it appears that the blog is showing the files being posted on the PC itself."

That's simply the local path of the source files when logged into the system where the source files are located and is accessible via the UNC shown in step 5 which is where ConfigMgr pulls the content from to in turn place on the DP which is where the clients will get the content from.

Jason | http://blog.configmgrftw.com | @jasonsandys


Thursday, August 3, 2017 6:38 PM

Jason,

I have added my files to a network share which should be picked up in the package when it's created. As for the batch file, I have it configured like this:

if not exist "C:\Program Files (x86)\DLI\DLI-KeyMon-x64" goto :exit copy /y "%~dp0Files2Copy\*.*" "C:\Program Files (x86)\DLI\DLI-KeyMon-x64" :exit

Would this be acceptable?


Thursday, August 3, 2017 6:48 PM

I've read through your blog again and I guess I am unsure of step 6. After rereading, I may want to keep your batch file unaltered, and have my package set to filecopy.bat C:\Program Files (x86)\DLI\DLI-KeyMon-x64 ?


Thursday, August 3, 2017 6:58 PM

Using Program Files (x86) will be problematic if you have any 32-bit systems in the environment.

Step six is just calling the batch file and passing the destination directory to it.

Jason | http://blog.configmgrftw.com | @jasonsandys


Friday, August 4, 2017 4:54 PM

Hi Jason,

The blog is working like a charm, with one minor problem. The tool is copying to C:\Program instead of the actual path: C:\Program Files (x86)\DLI\DLI-KeyMon-x64

Would doing this fix the issue? filecopy.bat "C:\Program Files (x86)\DLI\DLI-KeyMon-x64"


Friday, August 4, 2017 5:46 PM

As noted, Program Files (x86) can be problematic if you have 32-bit systems in the environment since that doesn't exist on a 32-bit system.

If you have no 32-bit systems that you will be running this on, then yes Program Files (x86) should work fine.

Jason | http://blog.configmgrftw.com | @jasonsandys


Friday, August 4, 2017 6:16 PM

Expect you didn't answer my question. I understand it becomes problematic if I am running this script on a 32bit OS, but I am not. All of my OS installs are 64bit.

The problem is the script from your blog is creating a directory called C:\Program instead of copying the files to the folder in Program Files (X86). My assumption here is that if I surround the path in quotes, it would use the full path name not just part of it?


Friday, August 4, 2017 6:43 PM

On your command-line yes otherwise the command-line parser sees the space as a terminating character.

So the command-line would be something like

filecopy.bat "C:\Program Files(x86)\xyz"

(with quotes)

Jason | http://blog.configmgrftw.com | @jasonsandys


Friday, August 4, 2017 7:28 PM

You assistance on this has been much appreciated! Thank you.