'Run Powershell script after the first one finished
How to modify the code be more neatly to make the first powershell function finished before starting the next one.
Echo Clean Windows\Temp Folder
Powershell.exe -Command "& {Start-Process Powershell.exe -ArgumentList '-ExecutionPolicy
Bypass -File %~dp0WinTempAllCleanCount.ps1' -Verb RunAs}"
Echo %errorlevel%
ping 127.0.0.1. /n 6
Timeout 5
REM Disk CleanUp
Echo Disk CleanUp
Powershell.exe -Command "& {Start-Process Powershell.exe -ArgumentList '-ExecutionPolicy
Bypass -File %~dp0DiskClean.ps1' -Verb RunAs}"
Echo %errorlevel%
#A.ps1
set-location $env:windir\temp -ErrorAction stop #
Change directory
$files = get-childitem -File #
Get all the files in this directory
$folders = get-childitem -directory #
Get all the folders in this directory
$count = ($files|measure).count #
($files|measure).count gives how
# many
files are in this collection.
$countfo = ($folders|measure).count #
($files|measure).count gives how
# many
files are in this collection.
Start-Sleep -s 5
write-host "There may be $($count) files to be deleted." #
Write that to the screen.
# $files | remove-item #
remove the files
write-host "There may be $($countfo) folders to be deleted." #
Write that to the screen.
# $folders | remove-item #
remove the files
$files | remove-item -Recurse -Force -ErrorAction SilentlyContinue #
For Windows/Temp folder
$folders | remove-item -Recurse -Force -ErrorAction SilentlyContinue #
For Windows/Temp folder
$files = get-childitem -File #
Get all the files in this directory
# after
the delete to find out how
# how
many remained.
$folders = get-childitem -directory #
Get all the folders in this directory
# after
the delete to find out how
# how
many remained.
$count2 = ($files|measure).count
$countfinal = $count-$count2 #
$countfo2 = ($folders|measure).count
$countfofinal = $countfo-$countfo2 #
write-host "$($count2) files remained. " -NoNewline
write-host "$($countfinal) files were deleted. " #
write-host "$($countfo2) folders remained. " -NoNewline #
write-host "$($countfofinal) folders were deleted. " #
Start-Sleep -s 8
#B.ps1
Get-ItemProperty -Path
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches*' | % { New-ItemProperty -Path $_.PSPath -Name StateFlags0001 -Value 2 - PropertyType DWord -Force }; Start-Process -FilePath CleanMgr.exe -ArgumentList '/sagerun:1' ##- WindowStyle Hidden
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
