将BIOS设置导出到CSV文件时数据类型问题

时间:2019-05-24 09:20:52

标签: powershell wmi powershell-remoting bios

我遇到了将字符串导出到CSV文件的问题。我的脚本是使用WMI查询和PowerShell从Lenovo笔记本电脑远程获取BIOS设置。我将结果导出到CSV文件。所有设置都可以导出,但是“ AvailableSettings”(BIOS设置选项)似乎遇到类型不匹配的问题。

输出文件如下:

CurrentSetting,"Status","AvailableSettings"
WakeOnLAN,"ACOnly","System.String[]"
EthernetLANOptionROM,"Enable","System.String[]"

代码:

$Computers = Get-Content -Path C:\temp\ComputerList.txt

foreach ($Computer in $Computers) {
    $Computer = $Computer -replace "`t|`n|`r",""

    $Get_manufacturer = (Get-WmiObject -ComputerName $Computer Win32_Computersystem).Manufacturer

    if ($Get_manufacturer -like "*lenovo*") {
        $manufacturer = "Lenovo"
        $selections = Get-WmiObject -ComputerName $Computer -Class Lenovo_GetBiosSelections -Namespace root\wmi
        $resultsLenovo = Get-WmiObject -ComputerName $Computer -Class Lenovo_BiosSetting -Namespace root\wmi | Where-Object CurrentSetting | ForEach-Object {
            $parts = $_.CurrentSetting.Split(',')
            [PSCustomObject]@{
                CurrentSetting = $parts[0]
                Status = $parts[1]
                AvailableSettings = $selections.GetBiosSelections($parts[0]).Selections.Split(',')
            }
        }

        $resultsLenovo | Export-Csv -Path "C:\temp\$Computer-BIOS-settings.csv" -NoTypeInformation -Delimiter ',' -Encoding ASCII
    }
    Clear-Variable -Name manufacturer
}

其他制造商也有更多的IF,但是这里没有在代码片段中包含它们。

将结果输出到Out-GridView时,似乎工作正常。

结果应该是这样的:

CurrentSetting,"Status","AvailableSettings"
WakeOnLAN,"ACOnly","Disable, ACOnly, ACandBattery, Enable"
EthernetLANOptionROM,"Enable","Disable, Enable"

有什么想法我要弄清楚哪里以及如何对类型进行分类?

0 个答案:

没有答案