首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我尝试使用Get-ADComputer、Get-WmiObject和Get-windowsfeature收集不同的信息

我尝试使用Get-ADComputer、Get-WmiObject和Get-windowsfeature收集不同的信息
EN

Stack Overflow用户
提问于 2021-11-08 20:18:51
回答 1查看 45关注 0票数 0

我正在尝试从我的广告中列出的所有计算机中收集不同的属性,但我无法获取重新收集的查询的格式

我运行get-adcomputer query

代码语言:javascript
复制
$computerList = Get-ADComputer -Filter 'Name -like "SCPW*" -and ObjectClass -eq "Computer"' | Select-Object -Property Name,objectClass` 

我从$computerlist中列出的所有计算机收集信息

代码语言:javascript
复制
$list = foreach ($computer in $computerList) {Get-WmiObject -Class Win32_Product | Select-Object -Property Name }
$WFeature = foreach ($computer in $computerList) {Get-windowsfeature | Where {$_.installed -Eq $true} | Select-Object -Property Name}
$Wrole = foreach ($computer in $computerList) {Get-WmiObject -Class Win32_ServerFeature -Property * | select pscomputername,name }

最后,我尝试在一个唯一的表中列出收集到的所有信息

代码语言:javascript
复制
%{[PSCustomObject]@{
        'ComputerName' = $computer.Name
        'features'     = $WFeature.name
        'Role'    = $Wrole.name
        'list'    = $list.name
    } } | Format-table

但是列出的表只有一行

代码语言:javascript
复制
ComputerName features                                                                  Role                                                                                       list            
------------ --------                                                                  ----                                                                                       ----            
SCPWEXC0101  {File-Services, FS-FileServer, Remote-Desktop-Services, RDS-RD-Server...} {Web Server (IIS), File Services, Print and Document Services, Remote Desktop Services...} {Microsoft Ap...

the table listed only in one line (screenshot)

如果有人给我一些帮助,我真的会非常感激,我正在学习PS,我真的迷失在这个问题上。我一直在运行PS5.1

谢谢!!

EN

回答 1

Stack Overflow用户

发布于 2021-11-08 21:26:14

您必须将查询放在每台计算机的循环中,以保持收集的信息与计算机名称之间的相关性。像这样的东西应该会让你开始:

代码语言:javascript
复制
$computerList = Get-ADComputer -Filter 'Name -like "SCPW*" -and ObjectClass -eq "Computer"'
$Result = 
foreach ($computer in $computerList) { 
    $CimSession = New-CimSession -ComputerName $computer.name

    [PSCustomObject]@{
        ComputerName         = $computer.Name
        WindowsFeatureList   = (Get-windowsfeature -ComputerName $computer.name | Where-Object { $_.installed } | Select-Object -Property Name) -join ', '
        W32ServerFeatureList = (Get-CimInstance -CimSession $CimSession -ClassName Win32_ServerFeature | Select-Object -Property Name) -join ', '
        W32ProductList       = (Get-CimInstance -CimSession $CimSession -ClassName Win32_Product | Select-Object -Property Name) -join ', '
    }
}
$Result
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69889470

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档