Powershell script

by deliyurek007 at 2013-03-24 03:27:53

Hi Guys,

I am newbie with Powershell script and I will learn each day.
But I have a question about a script maybe is this script for this forum to simple.

When I use :
Get-ChildItem “\fileserv1\Rappor\Fax” -recurse -include FileserverFax* -force | remove-item (with a task scheduler is waiting for YES, ALL , NO etc.)

Is still asking for permission like to confirm YES, ALL default permission, I try at the end confirm] and still get the question.
Also on the hidden files, folders. (files like: Thumbs.db, .ini, etc.)

How can I create a job that delete the files that doesn’t ask for permission and the job runs.

Kind regards,
by DonJ at 2013-03-24 18:14:39
I’m not sure that I understand what you are asking, but let me try.

You are saying that the script is prompting for Yes, No, etc., but that your script is running in Task Scheduler, so there is no way to respond.

You have added -Confirm] and that did not work?

Try also adding -force to the command.

Get-ChildItem does not show hidden files by default. Add -force to Get-ChildItem to display hidden files.
by deliyurek007 at 2013-03-25 00:33:25
Sorry Donj about my text.

Yes , I am looking for powershell command to make sure when I Run the script will delete automaticlly.

Get-ChildItem “H:\Users” -recurse -include "Access
" -force | remove-item

The item at Microsoft.PowerShell.Core\FileSystem::H:\Users\40401\TSPROFIL\Start Menu\Programs\Accessories 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"):

For each folder I have to click, Can I make this default so that run automaticlly. I try this also with the command -Confirm:$false and didn’t work.
Get-ChildItem “H:\Users” -recurse -include "Access*" -force | remove-item -Confirm:$false

Kind regards,
by DonJ at 2013-03-25 06:27:16
Try adding -force on Remove-Item.
by deliyurek007 at 2013-03-25 06:42:49
I try with the following command:
Get-ChildItem “H:\Users” -recurse -include "Access*" -force | -force -Confirm:$false

I get the error:
The term ‘-force’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spel
ling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:62
+ Get-ChildItem "H:\USERS" -recurse -include "Access*" | -force <<<< -Confirm:$false
+ CategoryInfo : ObjectNotFound: (-force:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

I try also with :
Get-ChildItem “H:\Users” -recurse -include "Access*" | -force -Confirm:$false
Get-ChildItem “H:\Users” -recurse -include "Access*" | -force

Same message no succes Donj. Is the powershell command OK or do I something wrong.

Kind regards,
by simark at 2013-03-25 07:03:38
Hi Hakan,

The following one-liner will delete all files and sub-folders under H] thats name match the "Access*" criteria.
Be cautious when using Remove-Item -Force -Recurse
Get-ChildItem -Path "H:\Users" -Recurse -Force -Include "Access*" | Remove-Item -Force -Recurse

You have to -Force the Remove-Item cmdlet to remove items without confirmation. If you have sub-fulders under "H:\Users" then you also have to add -Recurse to the Remove-Item cmdlet to allow it to remove sub-folders aswell.

The error you ran into [quote]The term ‘-force’ is not recognized as the name of a cmdlet,…[/quote] was due to that there is no cmdlet called -Force. It is a parameter of the Remove-Item cmdlet
by deliyurek007 at 2013-03-25 07:52:49
That works Simark thanks a lot for your help.
I will also thank you Donj for your help.

Kind regards,