Execute-Process Erroring Out in SCCM Task Sequence

I am attempting to set the hidden attribute on a few files that I copied using the Copy-File function in an SCCM Task Sequence. To do so, I’m using the attrib.exe program built into Windows. When I run the following three functions on my main machine in a non TS Environment, I have no issues. When this runs in a Task Sequence, the function errors out with a return code of -1073741502. The log shows the correct command is being executed.

Execute-Process -Path “attrib.exe” -Parameters “+h C:\file.exe”
Execute-Process -Path “attrib.exe” -Parameters “+h C:\file.xsl”
Execute-Process -Path “attrib.exe” -Parameters “+h C:\file.gif”

In the Task Sequence environment, I tried running these commands in the command prompt and was successful.

I then created a batch file (attribs.bat) with these commands and executed the batch file successfully through the command prompt. Finally, I called the batch file from the PSDT and encountered the same error as I originally had. This batch file also has logging functionality which were not created at the time of execution leading me to believe the PSDT is not successfully launching the batch file or the processes explained earlier.

Execute-Process -Path “attribs.bat”
Execute-Process -Path “cmd.exe” -Parameters “attribs.bat”

Please let me know if you have any suggestions or need any additional information from me.

Execute-Process -Path “cmd.exe” -Parameters “/c attribs.bat”

Also, be sure to name your batch files .cmd instead of .bat. There are subtle differences between how the two are processed (most of the time it’s no big deal tho)

You could use powershell for this aswell, which IMO is a little neater

$file= get-Item -Path "D:\temp\dummy.txt"
Set-ItemProperty -Path $file.FullName attributes -Value ((Get-ItemProperty $file.fullname).attributes -BXOR [io.fileattributes]::hidden)

… which would result in the value for the hidden attribute changing to the opposite of whatever it was before (or hidden if no value at all)

I haven’t fully tried this, but it could easily be looped through an entire directory with the following

$files = Get-ChildItem "C:\dummy\"
Foreach($file in $files)
Set-ItemProperty -Path $file.FullName attributes -Value ((Get-ItemProperty $file.fullname).attributes -BXOR [io.fileattributes]::hidden)

See this Hey Scripting Guy! Blog post for more details on it

EDIT: the code tags messes up the ", but I think that’s the only part… anyway be aware when copy pasting.