0

I am configuring Jenkins, and when the check out is performed, I need 2 folders to be deleted. I have created the script, which deletes all the bin folder. However, I want to delete all obj folder too.

Get-ChildItem -path C:\testFolderCheck 'obj' -Recurse -force |
Remove-Item -force -Recurse 
Get-ChildItem -path C:\testFolderCheck 'bin' -Recurse -force | 
Remove-Item -force -Recurse

When I am executing this scripts, only the bin folder is getting deleted. Is there any way of executing both scripts in one run?

2 Answers 2

1

You can pass an array of paths to the Get-ChildItem cmdlet :

Get-ChildItem [[-Path] <String[]> ] [[-Filter] <String> ] [-Exclude <String[]> ] [-Force] [-Include <String[]> ] [-Name] [-Recurse] [-UseTransaction] [ <CommonParameters>]

So try this:

Get-ChildItem -path 'C:\testFolderCheck\obj', 'C:\testFolderCheck\bin' -Recurse -force |
    Remove-Item -force -Recurse
Sign up to request clarification or add additional context in comments.

Comments

0
function clean
{
    Get-ChildItem -path C:\testFolderCheck 'obj' -Recurse -force | Remove-Item -force -Recurse 
    Get-ChildItem -path C:\testFolderCheck 'bin' -Recurse -force | Remove-Item -force -Recurse
}

clean 

One possibility to excute the script in one run is to define a function. Another possibility is to use the invoke-command with computername and your script as scriptblock (maybe the better way, if you do remoting).

Don´t be to hard -it´s my first post on stackoverflow :-)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.