Purge files content with exception of some shild files

Hi, i’m a begginer with powershell
I want to make a script to delete all files from a repertoire called mydocuments without touching some other shild files, for exemple :

if i have my document that have :
test4.doc …
a file with name MYWORk
i want to delete all the file in mydocument without touching the file call MYWORK.

get-childitem -path "FilePath" -Recurse -ne "MYWORk" | remove-item -Force
-ne For Not equal

but it dosent work correctly.

Any ideas,
Thanks in advance

Is not a helpful description. I’m sure you’ve got an error message. Please always post the complete error message. Error messages are important as they usually tell you what’s wrong. :wink:

Regardless of that - wheny oupoast code, error messages, console output or sample data please format it as code using the preformatted text button ( </> ),

Thanks in advance.

And … finally … when you carefully (re-)read the complete help for the cmdlet Get-ChildItem you will see there is no paramter -ne but -Exclude !!! :wink:

1 Like

Hi, sorry if it was a bad description, honestly i find -ne like not equal too

And -Exclude work perfectly thank you

get-childitem -path "C:\Path..." -Recurse -Exclude "file to exclude" | remove-item -Force

and here’s the ligne code if someone else need it.

Sorry, I didn’t get that.

But I’m glad it helped anyway. :+1:t4: :wink:

what i ment that i did find -ne in powershell suport too that’s why i use it it was like the inverse of -eq.
But thanks you did really help.

Could you please share a link to this documentation?

Thanks in advance. :+1:t4:

Sorry for last replay, i tried to find the link but i think i lost it.
ThanK you.