Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

remote registry array of computers. to determine value to be exported

$
0
0

hello, so I am trying to create a script now that reads the value from the registry of multiple remote computers and based on that value, executes a conditional statement that chooses what to add to my output. here is my code, TechNet worked once for me hoping it can help again. thanks.

edit: i should probably mention my problem eh, ok so the issue is that the test variable stays on whatever the last value was, when i output it...it is not unique for each machine.

$computers = Get-Content -Path C:\machines.txt
$computers = $computers.Trim()

$imp1 = "Type 1"
$imp2 = "Type 2"
$NOimp = "no type found"

foreach ($computer in $computers) {

$Reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$RegKey= $Reg.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion")
$Test1 = $RegKey.GetValue("test1")

}

if ($Test1 -eq 1) {
$computers | foreach-object {
  $biosInfo = get-wmiobject Win32_BIOS -computername $_
  $computerInfo = get-wmiobject Win32_ComputerSystem -computername $_
  
  new-object PSObject -property @{
    "ComputerName" = $_"Description" = $biosInfo.Description"SerialNumber" = $biosInfo.SerialNumber"Domain" = $computerInfo.Domain"Manufacturer" = $computerInfo.Manufacturer"Model" = $computerInfo.Model"Name" = $computerInfo.Name"NumberOfProcessors" = $computerInfo.NumberOfProcessors"ImpType" = $imp2
  }
  }| Sort ComputerName | 
        Select ComputerName,Description,SerialNumber,Domain,Manufacturer,Model,Name,NumberOfProcessors,"ImpType" | export-csv "C:\Users\Public\outputfile.csv" -notypeinformation
}
elseif ($Test1 -ne 1) {
 $computers | foreach-object {
  $biosInfo = get-wmiobject Win32_BIOS -computername $_
  $computerInfo = get-wmiobject Win32_ComputerSystem -computername $_
  new-object PSObject -property @{"ComputerName" = $_"Description" = $biosInfo.Description"SerialNumber" = $biosInfo.SerialNumber"Domain" = $computerInfo.Domain"Manufacturer" = $computerInfo.Manufacturer"Model" = $computerInfo.Model"Name" = $computerInfo.Name"NumberOfProcessors" = $computerInfo.NumberOfProcessors"ImpType" = $imp1
  }
  }| Sort ComputerName | 
        Select ComputerName,Description,SerialNumber,Domain,Manufacturer,Model,Name,NumberOfProcessors,"ImpType" | export-csv "C:\Users\Public\outputfile.csv" -notypeinformation
}



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>