Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Shell 

Powershell confirm delete

Hi.
I'm trying to use this powershell script;
Code
<#
The sample scripts are not supported under any Microsoft standard support
program or service. The sample scripts are provided AS IS without warranty  
of any kind. Microsoft further disclaims all implied warranties including,  
without limitation, any implied warranties of merchantability or of fitness for
a particular purpose. The entire risk arising out of the use or performance of  
the sample scripts and documentation remains with you. In no event shall
Microsoft, its authors, or anyone else involved in the creation, production, or
delivery of the scripts be liable for any damages whatsoever (including,
without limitation, damages for loss of business profits, business interruption,
loss of business information, or other pecuniary loss) arising out of the use
of or inability to use the sample scripts or documentation, even if Microsoft
has been advised of the possibility of such damages.
#>

#requires -Version 3
Function Clear-OSCTempFile
{
    #This function is used to delete temp files such as Internet temp file in windows 8
    #Get all items with ".tmp" in the $env:TEMP path
    $TempFiles =Get-ChildItem -Path $env:TEMP -Recurse -Force | Where-Object {$_.Extension -contains ".tmp" }
    #Call the function to delete them
    DeleteTemp $TempFiles
    #Get all items with ".tmp" in Temporary Internet Files
    $InternetTempPath = "C:\Users\$env:USERNAME\AppData\Local\Microsoft\Windows\Temporary Internet Files"
    $InternetTmpFiles= Get-ChildItem -Path  $InternetTempPath -Recurse -Force |Where-Object {$_.Extension -contains ".tmp"}
    #Call the function to delete them
    DeleteTemp $InternetTmpFiles  
}
Function DeleteTemp($Files)
{
    #This function is to delete the file in an array
    Foreach ($File in $Files)
    {
        $path = $File.FullName
        If($path -ne $null)
        {
            Try
            {
                #Delete the item
                Remove-Item -Path $path -Force -ErrorAction Stop
                Write-Host "Delete ""$path"" successfully."
            }
            Catch
            {
                Write-Warning """$path"":Access is denied. Please close the IE browser or related programs"
            }
        }
    }
}
Clear-OSCTempFile

And I want it to go automatically without needing to write "y" to confirm.

When I run the script I get
Code
Confirm
The item at C:\Users\Bruker\AppData\Local\Temp\nsl64FA.tmp has children and the Recurse parameter was not specified. If
you continue, all children will be removed with the item. Are you sure you want to continue?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"):

Any idea? Tried with the rescurse parameter but then the script does not run..
[Image: cpJG5qD.png]
What version of PowerShell are you running? Does your version and the author's version match?

Try this and check:

Code
$PSVersionTable.PSVersion
[Image: pia_banner_3.png]


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by samir5000Mar 13, 2025 01:32 PM 3 328 Mar 13, 2025 01:32 PM
Last Post: Bastille
[Shell] by PELockDec 9, 2024 09:42 AM 3 661 Dec 9, 2024 09:42 AM
Last Post: PELock
[Source] by QismonNov 27, 2024 04:29 AM 2 308 Nov 27, 2024 04:29 AM
Last Post: mikeyp