0

I want to clean a website before a deploy. In order to do that, I use WMIC to run remotely and Powershell to remove all the files except some specific ones:

WMIC /node:server /user:user /password:pass process call create "powershell -Command 'Get-ChildItem C:\Optima-QA2 -File -Name -Recurse -Force -Exclude .*\.7z, .*\.lic, [Ww]eb\.config | foreach($_) {remove-item $_}'"

but it seems to have problems with the pipe and the foreach, to parse and catch properly the command.

How can I do that? Is there other possibility to clean a website using regex for exclusions? PsExec is not working in the environment, so it's not an option to me, I'm afraid.

0

Try eliminating the pipe by calling Remove-Item directly:

Remove-Item (Get-ChildItem C:\Optima-QA2 -File -Name -Recurse -Force -Exclude .*\.7z, .*\.lic, [Ww]eb\.config) -WhatIf

The WhatIf parameter will show you what would happen without actually performing the removal. This is a great way to test what would be deleted without the parameter.

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.