Forums on Intune, SCCM, and Windows 11

Welcome to the forums. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your topics and posts, as well as connect with other members through your own private inbox!

PENDING Powershell not executing through sccm

  • Thread starter Thread starter jblackburn
  • Start date Start date
  • Replies Replies 9
  • Views Views 4K

jblackburn

Member
Messages
15
Reaction score
1
Points
3
I have a powershell script I'm trying to run as a program or a script through the new script section. The script won't work correctly and I'm not sure why. It executes and shows up in the task manager and then just sits there for 120 minutes until it kills itself :) The script is below. The first part of the script works because the registry values are present however cleanmgr doesn't execute. execmgr doesn't show an error as its technically running ok

The script itself works if I manually go to the machine and execute the script as an admin. It just won't work through the sccm client process.

Any ideas of possible alternatives? I'm trying to get rid of the Windows.old folder after a Win 10 inplace install

#create registry value
$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations"
New-ItemProperty -Path $regpath -Name "StateFlags1221" -PropertyType DWORD -Value 2 -Force | Out-Null
$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\update Cleanup"
New-ItemProperty -Path $regpath -Name "StateFlags1221" -PropertyType DWORD -Value 2 -Force | Out-Null
$regpath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\System error memory dump files"
New-ItemProperty -Path $regpath -Name "StateFlags1221" -PropertyType DWORD -Value 2 -Force | Out-Null

#start clean application
cleanmgr.exe /SAGERUN:1221
 
I haven't tested this script but did you try deploying this script using a task sequence ?. Give a try and let me know if that works.
 
Yes I've added it to my 1803 upgrade task sequence but it doesn't seem to work. I've now noticed the cleanmgr.exe shows up in task manager when I run it as an advertisement on a machine. It just sits there with Powershell on 0%. very odd as all my other powershell scripts now work but none of them call on an exe

I'm also trying this
 
* I pressed the wrong button :D


#Take OwnerShip of the files
TAKEOWN /f C:\Windows.old\*.*
#Set permissions for SYSTEM Account
ICACLS C:\Windows.old\*.* /Grant 'System:(F)'
#Delete the files
Remove-Item C:\Windows.old\*.*

but this again fails on the inplace upgrade task sequence I have it could be the nature of the task sequence
 
you need to add powershell component to your boot image. 1527221313789.png

oh, hang on... you are not using it for pxe imaging... ignore
 
Last edited:
Yea its post PXE. I've decided we'll run the PowerShell I have as a manual step afterwards when the tech does the system check before signing off and packing it away. I asked on TechNet but I just got trolled telling me the scheduler will sort it

Thanks for the above though Edy I didn't know you could add components into the WinPE!
 
yes, kind of

%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -executionPolicy unrestricted -noexit -file ".\DeleteWindowsOld.ps1"

The powershell runs I can see it taskviewer and the registry edits are made. It then calls cleanmgr.exe as I can see it in the taskviewer it then all just sits doing nothing
 
I put noexit in the command as it was running as part of a task sequence. I don't want the sequence to end until the powershell has ended naturally
 

Forum statistics

Threads
7,143
Messages
27,892
Members
18,190
Latest member
BaconBandit

Trending content

Back
Top