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