Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
**Desired Output:**

1. Match OS value with .TXT file values.
2. If Matching OS found get its whole value from TXT file.
3. Add Column Value "Type" having fixed value "windows"
4. Save values in TXT or CSV file.

**For Example:**
===============
192.168.1.1 windows DC CIS_Microsoft_Windows_Server_2016_RTM_(Release_1607)_Benchmark_v1.2.0-xccdf.xml
192.168.1.5 windows SCCMCB CIS_Microsoft_Windows_Server_2016_RTM_(Release_1607)_Benchmark_v1.2.0-xccdf.xml
192.168.1.7 windows WIN1020H2 CIS_Microsoft_Windows_Server_2016_STIG_Benchmark_v1.0.0-xccdf.xml


**TXT file values:**

=================
CIS_Microsoft_Windows_10_Enterprise_Release_20H2_Benchmark_v1.10.1-xccdf.xml
CIS_Microsoft_Windows_8.1_Workstation_Benchmark_v2.4.0-xccdf.xml
CIS_Microsoft_Windows_8_Benchmark_v1.0.0-xccdf.xml
CIS_Microsoft_Windows_Server_2012_R2_Benchmark_v2.4.0-xccdf.xml
CIS_Microsoft_Windows_Server_2016_RTM_(Release_1607)_Benchmark_v1.2.0-xccdf.xml
CIS_Microsoft_Windows_Server_2019_Benchmark_v1.2.1-xccdf.xml
CIS_Microsoft_Windows_Server_2019_STIG_Benchmark_v1.0.1-xccdf.xml
CIS_Red_Hat_Enterprise_Linux_7_Benchmark_v3.1.1-xccdf.xml

What I have tried:

**CODE:**

$result = 1..8 | ForEach-Object {
$ip = "192.168.1.$_"
if (Test-Connection -ComputerName $ip -Count 1 -Quiet -ErrorAction "SilentlyContinue") {
try{
Get-wmiObject -ClassName Win32_operatingsystem -ComputerName $ip -ErrorAction Stop |
Select-Object @{Name = 'Host'; Expression = {$_.CSName}}, @{Name = 'IP'; Expression =
{$ip}}, @{Name = 'OS'; Expression = {$_.Caption}}
}
catch{
write-warning "Unable to get WMI info from '$ip'" |
out-file "results.txt" -append
}
}
else {
write-warning "Unable to connect to '$ip'" |
out-file "results.txt" -append
}
}
$result



**Current Result:**

Host IP OS
---- -- --
DC 192.168.1.1 Microsoft Windows Server 2016 Standard
SCCMCB 192.168.1.5 Microsoft Windows Server 2016 Standard
WIN1020H2 192.168.1.7 Microsoft Windows 10 Enterprise Evaluation
Posted
Updated 4-Jun-21 1:42am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900