/build/static/layout/Breadcrumb_cap_w.png

Powershell 7 Kscript doesn't want to run

Hi there everyone. First time long time...


I've installed Powershell v7.1.3 to a windows server 2012 R2 box and can successfully run the command: Clear-RecycleBin -Force from the local desktop.

I've attempted to implement a daily script to automate this task. Efforts so far have been unsuccessful. Im stumped as to why.

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/clear-recyclebin?view=powershell-7.1

NOTE! pwsh.exe is the Powershell7 executable that can be run from anywhere as its added to the PATH system variable.


I've tried two methods, both run as 'local system':

Using a dependency file (the file is simply a one liner Clear-RecycleBin -Force)

Debug Log

Running kbot: runkbot 119 1622608041 KBotScript::LogScriptInfo - Start id=119 name=Empty Recycle Bin version=1622608041 type=policy execute disconnected=false logged_off=true execute events KBotScript::LogScriptInfo - Finish KBotScript::LogScriptInfo - Start id=119 name=Empty Recycle Bin version=1622608041 type=policy execute disconnected=false logged_off=true execute events KBotScript::LogScriptInfo - Finish KBotScriptManager::CleanupDependencies - clean up dependencies in kbot directory C:\ProgramData\Quest\KACE\kbots_cache\\packages\kbots\119\ CleanupDependencies: file Clear-RecycleBin.ps1 is part of the dependency list, keep the file runkbot ----- launching [path='C:\ProgramData\Quest\KACE\kbots_cache\packages\kbots\119' program='pwsh.exe' parms='-nologo -executionpolicy bypass -WindowStyle hidden -noprofile -file "Clear-RecycleBin.ps1"' wait='true'] ----- runkbot ----- completed [exitCode=0] -----


Or calling the command as part of the parameters:

Debug Log

Running kbot: runkbot 119 1622610064 KBotScript::LogScriptInfo - Start id=119 name=Empty Recycle Bin version=1622610064 type=policy execute disconnected=false logged_off=true execute events KBotScript::LogScriptInfo - Finish KBotScript::LogScriptInfo - Start id=119 name=Empty Recycle Bin version=1622610064 type=policy execute disconnected=false logged_off=true execute events runkbot ----- launching [path='' program='pwsh.exe' parms='-executionpolicy bypass -WindowStyle hidden -noprofile -Command "Clear-RecycleBin -Force"' wait='true'] ----- runkbot ----- completed [exitCode=0] -----


Can anyone spot where I'm going wrong? I'll add more information if its required.


0 Comments   [ + ] Show comments

Answers (1)

Posted by: JasonEgg 3 years ago
Red Belt
0

Instead of using "Launch a program..." try "Run a batch file..." with your one line:

pwsh.exe -executionpolicy bypass -WindowStyle hidden -noprofile -Command "Clear-RecycleBin -Force"

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ