我有一个脚本,它从一个或多个服务器收集信息,并通过将各种功能传递给远程会话(主要作为数组返回来显示):
$PSSession = New-PSSession -ComputerName $comp -Credential $fetchCreds -Name $server
$buildlogsuccess = Invoke-Command -Session $pssession -ScriptBlock ${function:check-buildlog} -ArgumentList $domain
$chocologstatus = Invoke-Command -Session $pssession -ScriptBlock ${function:check-choco}
$KMSvalues = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-winlicense}
$parentOU = get-ParentOU (Get-ADComputer -Server $dc -SearchBase $searchbase -Filter {name -eq $server} -Credential $fetchCreds) | select -expand parentou
$SCCMcheck = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-sccmstatus}
$scomcheck = Invoke-Command -Session $PSSession -ScriptBlock ${function:get-scomstatus} -argumentlist $scom
$AV = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-avstatus}
$wfirewall = Invoke-Command -Session $PSSession -ScriptBlock {(get-service MpsSvc).status}
$net35 = Invoke-Command -Session $PSSession -ScriptBlock {(Get-WindowsFeature NET-Framework-Core).installed}
$admins = Invoke-Command -Session $PSSession -ScriptBlock ${Function:check-admins}
$DomainComms = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-domaininfo}
$bigfix = Invoke-Command -Session $PSSession -ScriptBlock ${Function:get-bigfix}
#clean up the remote session
Remove-PSSession -Name $server
[PSCustomObject]@{
ServerName = $comp
"Physical/Virtual" = $Devicetype
"IP Address" = $device.IPAddresses.ipaddress
"Domain" = $DomainComms[4]
"Build Script Found, Completed" = [string]$buildlogsuccess[0] + [string]"," + [string]$buildlogsuccess[1]
"Choco Package Install Finished" = $chocologstatus
"KMS License Status, Retry" = [string]$KMSvalues[0] + [string]"," + [string]$KMSvalues[1]
"Parent OU" = $parentOU
"VM Tools Version, Status" = "$vmtoolsversion,$vmtoolsstatus"
"SCCM Client, Version,Last Comms" = ([string]$SCCMcheck[0] + [string]"," + [string]$SCCMcheck[1] + [string]"," + [string]$SCCMcheck[2])
"SCOM Client, Conn Status" = [string]$scomcheck[0] + [string]"," + [string]$scomcheck[1]
"McAfee Framework Installed, Running" = [string]$AV[0] + [string]"," + [string]$AV[1]
"McAfee Vcan Installed, DAT Date" = [string]$AV[2] + [string]"," + [string]$AV[3]
"SEP Endpoint Protection Installed, Running" = [string]$AV[4] + [string]"," + [string]$AV[5]
"SEP Vcan Installed, DAT Date" = [string]$AV[6] + [string]"," + [string]$AV[7]
"BigFix Client, Version, Install Date" = [string]$bigfix[0] + [string]"," + [string]$bigfix[1] + [string]"," + [string]$bigfix[2]
"Windows Firewall Status" = $wfirewall
"Net 3.5 Installed" = $net35
"Connection to domain OK, Current DC, AD Site" = [string]$DomainComms[0] + "," + [string]$DomainComms[1] + "," + [string]$DomainComms[2]
"DelAdmin Groups in Admins" = $admins[1]
"Applied GPOs" = $DomainComms[3]
}
输出(大部分)按预期显示,除了最后一个字段在列表输出中显示正常且Out-GridView
时,使用Export-Csv
时没有正确输出(或复制)从Out-GridView
)正确地导入Excel:
ServerName : serverA.abc.com Physical/Virtual : Virtual IP Address : 10.20.30.40 Domain : abc.com Build Script Found, Completed : Found C:\tre\w32\Logs\Installer.log,True Choco Package Install Finished : False: can't find C:\ProgramData\chocolatey\logs\chocolatey.log KMS License Status, Retry : True,N/A BigFix Client, Version, Install Date : False,N/A,N/A Windows Firewall Status : Running Net 3.5 Installed : True Connection to domain OK, Current DC, AD Site : True,dc1.abc.com,Default-First-Site GG_admin_serverA in Admins : False DelAdmin Groups in Admins : abc\a-groupname-here Applied GPOs : SOE Server GPO 1 SOE Server GPO 2 Some-other-policy A group policy name - Infrastructure SOE Server GPO 1 SOE Server GPO 2 Some-other-policy A group policy name - Infrastructure SOE Server GPO 1 SOE Server GPO 2 Some-other-policy A group policy name - Infrastructure
当该元素是多行输出时,是一种包装数组元素输出的方法,例如,对于CSV,HTML等。
例如,当我从Out-GridView
复制到Excel或Export-Csv
时,应用了GPO'字段最终显示其他行中的值&它应该在哪里的列。
答案 0 :(得分:1)
这是否就像指定值应该是字符串一样简单?
"Applied GPOs" = "$($DomainComms[3])"
否则,您需要操作数组以指定每个元素之间应使用的字符。例如新行的`n :
"Applied GPOs" = $DomainComms[3] -join "`n"