合并powershell脚本

时间:2016-02-11 07:36:25

标签: powershell

我正在配置Jenkins,当执行签出时,我需要删除2个文件夹。我创建了脚本,删除了所有bin文件夹。但是,我也要删除所有obj文件夹。

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

执行此脚本时,只会删除bin文件夹。有没有办法在一次运行中执行这两个脚本?

2 个答案:

答案 0 :(得分:1)

您可以将一组路径传递给Get-ChildItem cmdlet:

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

所以试试这个:

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

答案 1 :(得分:0)

expect

在一次运行中执行脚本的一种可能性是定义一个函数。另一种可能性是使用 invoke-command和computername以及你的脚本作为scriptblock (如果你进行远程处理,可能是更好的方法)。

不要难以成为我在stackoverflow上发表的第一篇文章: - )

相关问题