0
如何以CSV格式获取作业输出。当我执行下面的命令时,我会在屏幕上显示输出,但是当我将它导出到CSV时,它不具有相同的格式。CSV格式的开始作业输出
$wmidiskblock = {
Get-WmiObject -ComputerName $args[0] -Class Win32_LogicalDisk -Filter "DeviceID='C:'" |
Select-Object Size, Freespace
(Test-Connection -ComputerName $args[0] | Select-Object -ExpandProperty IPV4Address) |
Select-Object IPAddressToString -Unique
Get-Service -ComputerName $args[0] | ? {
($_.DisplayName -match "VMWARE") -and
($_.Name -notmatch "mbcs") -and
($_.Name -notmatch "vmvss") -and
($_.Name -notmatch "vmware-autodeploy-waiter") -and
($_.Name -notmatch "vmware-network-coredump") -and
($_.Name -notmatch "VMWareNetworkCoredumpWebserve") -and
($_.Name -notmatch "vsan-health")
} -ErrorAction Stop
}
$com = @()
$com = "Server-x" , "Server-y"
$pop = @()
foreach ($ser in $com) {
[array]$pop += Start-Job -ArgumentList $ser -ScriptBlock $wmidiskblock -Name top1
}
Get-Job -Name top1 | Receive-Job -Keep
实际输出:
Size : 64422408192 Freespace : 4908081152 RunspaceId : cdb3xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx IPAddressToString : x.x.x.x RunspaceId : cdb3xxxxx-xxxx-xxxx-xxxx-xxxxxxxxx Status : Running Name : client_service DisplayName : VMware Horizon Client Status : Running Name : ftnlsv3hv DisplayName : VMware Netlink Supervisor Service Status : Running Name : ftscanmgrhv DisplayName : VMware Scanner Redirection Client Server-x
所需的输出(如CSV文件):
Server Totalspace in GB Freespace in GB IP VMware ESX Agent Manager VMware Inventory Service Server-x 100 36 144.215.150.67 Running Running
当我尝试下面的命令,它搞砸了所有格式 Get-Job -Name top1 | Receive-Job -Keep |格式 - 表格* 大小可用空间PSComputerName RunspaceId PSShowComputerName ---- --------- -------------- ------------ ----------------- 64422408192 4909293568 localhost 9e149962-c2e4-47c5-a83a-81e6c4f8c92a False – SUN