我需要在PowerShell中将两个输出或两个PSCustomObject合并为一个。例如,
$services = Get-Service | Select Name, Starttype,Status
$processes = Get-Process | Select ID
我需要带有表头Name, Starttype, Status, ID的输出。
我已经尝试创建CSV并将它们连接在一起,但问题是进程ID始于服务完整输出结束时。我需要它们同时进行。
第二,我尝试创建PSCustomObjects,但没有成功。
请帮我提供PowerShell代码。
我要实现的实际代码。
**$exclusionItems = @()
$OasHighItems = @()
foreach($item in $items){
$exclusionItems += [PSCustomObject]@{
EXCLUSION_BY_NAME_OR_LOCATION = $item.EXCLUSION_BY_NAME_OR_LOCATION
EXCLUSION_EXCLUDE_SUBFOLDERS = $item.EXCLUSION_EXCLUDE_SUBFOLDERS
EXCLUSION_ON_READ= $item.EXCLUSION_ON_READ
}
}
foreach($oas in $oashigh){
$oashighItems += [PSCustomObject]@{
OAS_PROCESSES_LIST = $oas
}
}
$Array = @()
$Array = $exclusionItems,$oashighItems
$Array | Update-FirstObjectProperties | Export-Excel $ExcelParams -TableName Table -Show**
Get-Service
中的项目与Get-Process
中的项目关联起来的? - Lee_Dailey