Como posso fazê-los rodar silenciosamente em segundo plano?
Aqui está meu script do PowerShell:
rm C:\*.jpg
rm C:\*.doc
rm C:\*.pptx
rm C:\*.xls
rm C:\Users\*.jpg
rm C:\Users\*.doc
rm C:\Users\*.pptx
rm C:\Users\*.xls
# set var for username
$yourUser = $env:USERNAME
rm C:\users\$yourUser\*.jpg
rm c:\users\$yourUser\*.doc
rm c:\users\$yourUser\*.pptx
rm c:\users\$yourUser\*.xls
E, se necessário, aqui está o XML para o PS Script (Tarefa agendada exportada):
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2022-06-23T15:11:00.2977928</Date>
<Author>MyDomain\MyUser</Author>
<Description>Nuke annoying AV junk files</Description>
<URI>\PS_Nuke_Annoying_files.ps1</URI>
</RegistrationInfo>
<Triggers>
<CalendarTrigger>
<Repetition>
<Interval>PT1H</Interval>
<StopAtDurationEnd>false</StopAtDurationEnd>
</Repetition>
<StartBoundary>2022-06-23T15:08:58</StartBoundary>
<Enabled>true</Enabled>
<ScheduleByDay>
<DaysInterval>1</DaysInterval>
</ScheduleByDay>
</CalendarTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-12-1-679272179-1229781794-976310157-3256474971</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>true</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT1H</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Temp\PS_Nuke_annoying_files.ps1</Command>
</Exec>
</Actions>
</Task>
Para evitar ver o pop-up da janela de comando do PowerShell de uma tarefa agendada:
SYSTEM
contexto e, em seguida, codifique sua$yourUser
variável para uma string de conta de usuário conhecida; ou ( mais perigosamente ), adicione-Recurse
ao final dasrm C:\Users
linhas (Remove-Item) em seu script para impactar todas as pastas e subpastas C:\Users.C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
. Altere Adicionar argumentos (opcional) para-NoLogo -NonInteractive -WindowStyle Hidden -File C:\Temp\PS_Nuke_annoying_files.ps1
-Confirm:$false -Force -ErrorAction SilentlyContinue
no final de cada linha rm (Remove-Item) em seu script, para garantir que você nunca seja solicitado.