How to stop getting prompted to "Confirm"
-
28. července 2011 0:57
Hello,
I have some Windows Server 2008 systems that I'm trying to run a powershell script on to delete some temp files, but I keep getting prompted with "Confirm... Y [Yes] [A] Yes to All...... ect" Is there a way to bypass the Confirm?
Thanks,
Tom
Tom Martin Email: tmartin@caa.com
Všechny reakce
-
28. července 2011 1:04
If you are using Remove-Item cmdlet use confirm switch like in below example
Remove-Item .\v.txt -Confirm:$false
With kind regards
Krystian Zieja
http://www.projectenvision.com
Follow me on twitter
My Blog
Need help with your systems?- Navržen jako odpověď A.Hultgren 28. července 2011 4:55
- Označen jako odpověď martit01 28. července 2011 16:28
- Zrušeno označení jako odpověď martit01 28. července 2011 18:17
- Zrušeno navržení jako odpověď martit01 28. července 2011 19:03
-
28. července 2011 1:16
Hi Krystian,
I'm using the below command typed directly into PowerShell just for testing purposes. So, I should just be able to add -Confirm:$false to the end and it should not prompt me to Confirm?
get-childitem C:\inetpub\logs\LogFiles -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction SilentlyContinue
Thanks,
Tom
Tom Martin Email: tmartin@caa.com -
28. července 2011 2:24Yes it should work by just appending -Confirm:$false at the end
With kind regards
Krystian Zieja
http://www.projectenvision.com
Follow me on twitter
My Blog
Need help with your systems? -
28. července 2011 4:36
Yes, if you set $confirm to false explicitly, it shouldn't prompt you to confirm.
get-childitem C:\inetpub\logs\LogFiles -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction SilentlyContinue -Confirm:$false
Alternatively, you can try -force parameter as well.
get-childitem C:\inetpub\logs\LogFiles -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction SilentlyContinue -Force
PS: Test above changes before trying out in production environment.
Thanks,Sitaram Pamarthi
Blog : http://techibee.com
Twitter:https://twitter.com/#!/pamarths
- Označen jako odpověď martit01 15. srpna 2011 16:31
-
28. července 2011 18:26
I just added -Confirm:$false to the end, but when I run the command locally on the server I'm still getting the following:
Confirm
The item at
Microsoft.Powershell.Core\FileSystem::C:\inetpub\logs\LogFiles\W3SVC1 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”):
I then tried it with –Force, but I received the same Confirm prompt.
Tom Martin Email: tmartin@caa.com -
28. července 2011 20:05Looking at the command you're running.. it will remove both files and folders. If it finds an old folder, it will attempt to remove it (and its contents) regardless if the files within it has been recently accessed or modified. Is this the intent?
Andreas Hultgren
MCTS, MCITP
http://ahultgren.blogspot.com/ -
28. července 2011 21:45
Yes, it should remove anything older than 14 days.... files or folders / folders and files.
Thanks,
Tom
Tom Martin Email: tmartin@caa.com -
29. července 2011 4:38
Do you mind posting your code here for better clarity? I generally delete all temp files in c:\windows\temp with below code. I face no Confirm prompts.
$TempFiles = Get-ChildItem c:\windows\temp -include *.tmp -recurse
$TempFiles | foreach ($_) { remove-item $_.Fullname -force}
Thanks,Sitaram Pamarthi
Blog : http://techibee.com
This posting is provided AS IS with no warranties or gurentees,and confers no rights
-
29. července 2011 5:17
Yes, it should remove anything older than 14 days.... files or folders / folders and files.
Thanks,
Tom
Tom Martin Email: tmartin@caa.comWhat I mean is the folders that are older than 14 days can still contain other folders and files that have been used recently. The command will try to delete that folder and its files anyway regardless of the files it contains are new or old.
Andreas Hultgren
MCTS, MCITP
http://ahultgren.blogspot.com/ -
29. července 2011 16:19
Here’s the code we are using to delete anything older than 14 days. Any suggestions is much appreciated. Thanks
get-childitem C:\inetpub\logs\LogFiles -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction SilentlyContinue -Confirm:$false
Tom Martin Email: tmartin@caa.com -
31. května 2012 20:37
This has probably already been answered but I was running into the same problem as you and couldn't find an answer.
Maybe if I post it here I will be able to find it the next time I run into it. :-)
I think this will work for you
get-childitem C:\inetpub\logs\LogFiles -include *.log -recurse | where-object { $_.LastAccessTime -lt (Get-Date).AddDays(-14) -and $_.LastWriteTime -lt (Get-Date).AddDays(-14) } | remove-item -ErrorAction SilentlyContinue -Confirm:$false
replace *.log without ever wildcard you need.
I was executing this
get-childitem -Recurse c:\logs\ | where {$_.LastWriteTime -le $now.AddDays(-30)} | del -whatif
and getting the same as you
Confirm
The item at
Microsoft.Powershell.Core\FileSystem::C:\logs\blah 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?
I replaced it with
get-childitem -Recurse c:\logs\ -include *log*| where {$_.LastWriteTime -le $now.AddDays(-30)} | del -whatif
and like magic no more prompts.
- Upravený thisissilly2 31. května 2012 20:41
-
19. června 2012 19:05
Hello Folks,
I'm having this issue with the "Confirm" dialog continuously popping up, no matter what combination of parameters I try. I've been reading this blog and tried using multiple combinations, to no avail.
Here is my command: Get-ChildItem 'c:\builds\testing' -recurse | where {$_.LastWriteTime -le (Get-Date).AddDays(0)} | del
-ErrorAction SilentlyContinue -Confirm:$false
If any one can help it would be greatly appreciated.
NOTE: I also set the $ConfirmPreference = "None"
Thanks In Advance!
Willie J. Pee
-
19. června 2012 20:54
Hello Folks,
I was able to solve this probably, with some internal help.
Here is my command I used to suppress the confirm dialog that I was getting:
Get-ChildItem c:\builds\testing -recurse | where-object {$_.LastWriteTime -le (Get-Date).AddDays(0)} | remove-item -force
-recurse
I hope this will be of some help to someone else that is having the same problem.
Thanks,
Willie J. Pee
- Upravený Willie James 19. června 2012 21:26
-
9. června 2013 15:42
Hello,
Does anybody know how can I add exclusions by folder(and all its contents) to this script ?
I have 3-4 folders and their content which I would like to keep!
thanks!
-
9. června 2013 20:19
Hi,
You can use the existing where clause to exclude the folders. If you still have questions, you're probably better off starting a new thread, as this one is old and already marked as answered.