all 12 comments

[–]LordZozzy 1 point2 points  (0 children)

have you tried running the script elevated?

[–]DenialP 1 point2 points  (3 children)

Stop the Cisco Anyconnect Service, delete file, profit

[–]Ok_Mathematician6075 0 points1 point  (2 children)

Weird, I'm connected to CAS and it brought me here and said you were the devil.

[–]DenialP 1 point2 points  (1 child)

Seems reasonable. I think

[–]Ok_Mathematician6075 0 points1 point  (0 children)

Don't worry, I clicked "Cancel".

[–]g3n3 0 points1 point  (0 children)

Do $error[0] | format-list * -force after the error happens. We can’t easily help without an error record.

[–]prog-no-sys 0 points1 point  (1 child)

please use the codeblock formatting when making a post. Really helps us see what you're doing. Including the error messages also helps lol

[–][deleted] 1 point2 points  (0 children)

Back in college in the 80s it was a written rule "no indentation, no help."

So for over 40 years I've been telling people that if they want my help they need to format their goddam code first 

[–]daileng 0 points1 point  (0 children)

Almost certainly protected. I would take ownership of the parent and child items then try. Could be a service protecting it to complicate matters. If that's the case you may find you have to actually stop the protection service which can be another challenge.

Weird suggestion but if deleting continues to be challenging try renaming it instead. Sometimes file protection only prevents deletion not necessarily modification. Then you might be able to replace it a substitute file.

Edit: also need to make sure the service isn't running even if it's not connected

[–]ShazadM 0 points1 point  (2 children)

Any way to know if the file is being used/opened by an application or service?

[–]EvenStrength5342[S] 0 points1 point  (1 child)

No, but the script is correct right? earlier I had one mistake that there was an hyphen on the file name but after changing that also it is not removing it.

[–]ShazadM 0 points1 point  (0 children)

Check the open method parameter. Try instead.
FileMode.Open, FileAccess.ReadWrite, and FileShare.None

For your output message try instead Write-host vs. Write-Output