我正在尝试创建Get-Command cmdlet的别名(命名为which),如果我不发送任何参数,它就不会运行(因为如果它在没有参数的情况下运行,它会输出所有可用的命令) .
我知道这可以使用函数来完成,但我想保留选项卡完成功能,而不必编写一个相当大的函数来放入我的$PROFILE 中。
简而言之,我只希望别名在传递参数时起作用。
基于如何并行执行PowerShell函数多次?,我能够做到这一点,同时停止所有正在运行的作业。
# Run this in parallel
$stopService {
param($service)
Stop-Service -Name $service.name -Force
}
$services = Get-Services | Where-Oject {$_.name -like "*XYX_*"}
Foreach($service in Sservices) {
Start-Job -ScriptBlock $stopService -ArgumentList $service
}
$doSomethingElse
Run Code Online (Sandbox Code Playgroud)
但是我怎样才能修改代码,以便我所有的并行作业先于我完成呢$doSomethingElse?有点像join()命令?
我有一组正在运行的作业。
PS C:\vinith> Get-Job
Id Name PSJobTypeName State HasMoreData Location Command
-- ---- ------------- ----- ----------- -------- -------
2 scvmm2012-vin BackgroundJob Running True localhost Param...
4 scom2012sp1-vin BackgroundJob Running True localhost Param...
6 scorch2012-vin BackgroundJob Running True localhost Param...
8 scsm2012sp1-vin BackgroundJob Running True localhost Param...
10 spfoundation BackgroundJob Running True localhost Param...
Run Code Online (Sandbox Code Playgroud)
我想要一个进度条显示,直到作业正在运行,并且在 powershell 中作业状态变为“已完成”时应该说已完成