从Group-Object获取值

时间:2015-10-05 19:46:34

标签: powershell

使用我以前的帖子(这里:Remove Duplicate XML Nodes in PowerShell

这是我的代码:

#Load XML file into $catalogXML
[xml]$catalogXML = (Get-Content (C:\test.xml))

$softwareVersionsArray = $catalogXML.catalog.software
$softwareToBeInstalled = $softwareVersionsArray|Group-Object name|ForEach-Object {$_.Group[0]}

这是我目前输出的$ softwareToBeInstalled:

name            version        installer_location                      
----            -------        ------------------                      
MozillaFirefox  31.3.0        /Mozilla/Firefox/31.3.0.exe             
Arduino         7.8           /Arduino/7.8.exe                        
GoogleChrome    35.7          /Google/Chrome/35.7.msi

使用For循环,我想从我的组对象中获取值($ softwareToBeInstalled)并将它们放入变量(例如$ softwareName,$ softwareVersion等)。

1 个答案:

答案 0 :(得分:0)

您需要$softwareToBeInstalled数组上的简单foreach ($soft in $softwareToBeInstalled) { $softwareName = $soft.name $softwareVersion = $soft.version $softwareLocation = $soft.installer_location Write-Host "$softwareName $softwareVersion $softwareLocation" } 循环:

#include<stdio.h>
#include<string.h>
int main()
{
    int i;
    char imeino[100]="\r\n865733024598757 OK\r\n";
    char data[20];
    for(i=2;i<17;i++)
        {
            data[i-2]=imeino[i];
        }
    data[i-2] = '\0';
    printf("%s",data);
    return 0;
}