Powershell - 输出结果一个接一个而不是水平输出

时间:2018-03-02 14:39:31

标签: powershell object

我正在使用:

Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName,InstallDate

返回:

Microsoft Visual C++ 2012 x64 Additional Runtime - 11.0.61030                           20180205           
Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161                          20161005           
Microsoft Policy Platform                                                               20170927           
Configuration Manager Client                                                            20171019           
Screen Pass 64 v6.6.2                                                                   20170927   

操纵对象以获取:

的逻辑是什么
Microsoft Visual C++ 2012 x64 Additional Runtime - 11.0.61030
20180205

Microsoft Visual C++ 2008 Redistributable - x64 9.0.30729.6161
20161005      

详情如下:

$logiciels = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | Select-Object DisplayName, InstallDate, Usager | out-string

该变量正传递给:

$global:infos_finales = @"
DN:$OU2

Lieu: $lieu

Noyau: $noyau - $version_noyau

Rôle: $role

Monté le: $datemontage

Adresse IP: $IPAddress

Adresse MAC: $MACAddress3

Modèle: $modele1 - $modele2

Redémarré le : $BootTimeFinal

__________________________________________________________________

Utilisateur: $user2

Connecté depuis : $temps2
$info_user2

$logiciels


"@

包含所有信息的$ infos_finales对象显示在表单中的richtextbox中(所有这些都发生在powershell GUI中):

$richtextbox1.Text = $infos_finales

这一切都有效,但格式化是不合适和丑陋的,这就是为什么我更喜欢它垂直,因为我不想让文本框suuuper宽,以适应所有信息。enter image description here

编辑后编辑,使用最终解决方案:

$global:logiciels = Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" |
        ForEach-Object {

            if ($_.DisplayName)
            {

                "$($_.DisplayName)"
                "$($_.InstallDate)"
                "$($_.Usager)"
                 ""
            }

        } | out-string

1 个答案:

答案 0 :(得分:2)

如果你真的想把它钉在那种格式上,你可以使用这样的东西:

Get-ItemProperty "hklm:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" |  
    ForEach-Object {
        If($_.DisplayName -and $_.InstallDate ){
            "$($_.DisplayName)"; "$($_.InstallDate)"; ''
        }
    }