powreshell function cleanup 1

powreshell function cleanup

function  CleanUp {
   # Delete directory content
   Get-ChildItem -Path ($PSScriptRoot + "\Files") -Recurse | ForEach-Object { $_.Delete()}
   Get-ChildItem -Path ($PSScriptRoot + "\Temp") -Recurse | ForEach-Object { $_.Delete()}
   Get-ChildItem -Path ($PSScriptRoot + "\Out") -Recurse | ForEach-Object { $_.Delete()}
}

Here is what the above code is Doing:
1. It’s creating a function called CleanUp.
2. It’s using Get-ChildItem to get all the files and folders in the Files, Temp, and Out folders.
3. It’s using ForEach-Object to loop through each file and folder and delete it.

Now, let’s add a call to the CleanUp function at the end of the script.

Similar Posts