2017-06-27 31 views
0

我具有从一个或多个服务器收集信息,并通过使各种功能以远程会话显示它(即作为阵列基本上返回的脚本:包装输出

$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出现OK,不输出正确使用Export-Csv时(或正确复制到Excel从Out-GridView):

 
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”字段最终显示值在其他行的&列之外。

+1

请提供期望的和实际CSV输出的采样(如文本,而不是屏幕截图)。 –

+0

请再次提供所需和实际** CSV输出**的样本。 –

回答

1

这是否像指定值应该是字符串一样简单?

"Applied GPOs" = "$($DomainComms[3])" 

否则,您将需要操作数组来指定每个元素之间应该使用哪个字符。新线如

"Applied GPOs" = $DomainComms[3] -join "`n"