none
Get OEMInformation from list of workstations RRS feed

  • Question

  • I am trying to get registry keys with the value OEMInformation from a list of computers but can't seem to get it to work. What am I missing?

    $strMachineName = import-csv C:\temp\PCs.csv
    foreach ($line in $strMachineName)
    {
        try {
            $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $line.computer)
            $regkey = $reg.OpenSubkey("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion")
            $serialkey = $regkey.GetValue("OEMInformation")

            ('"{0}","{1}"' -f $line.computer, $OEMInformation) | out-file C:\temp\stdout.csv -append -encoding ascii
        } catch {
            ('"{0}","{1}"' -f $line.computer, $_) | out-file C:\temp\stderr.csv -append -encoding ascii
        }
    }
    Friday, May 16, 2014 6:45 PM

Answers

  • Please look carefully at the code you are trying to use.  You need to think about what you are doing. Ther are obvious issues with what you are asking for.  You are also not attempting to understand the solution.

    In PowerShell there is help and it has many examples.  Always start by reviewing the help. Look at examples in the repository.  Read the "learning" resources.


    ¯\_(ツ)_/¯

    • Marked as answer by Newbie 1 Tuesday, May 27, 2014 4:23 PM
    Tuesday, May 27, 2014 3:46 PM

All replies

  • Hi,

    The first thing I see is that you're using $OEMInformation in your string formatting when you've named the variable $serialkey.

    If that doesn't fix your issue, you'll need to explain what's actually going wrong with your script.


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Friday, May 16, 2014 7:49 PM
  • OEMInformation is a key - not a value:

    Start small with this until you understand how it works:

    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:computername)
    $regkey=$reg.OpenSubkey('SOFTWARE\Microsoft\Windows\CurrentVersion\OemInformation')
    $regkey.GetValue('Manufacturer')
    


    ¯\_(ツ)_/¯

    Friday, May 16, 2014 8:06 PM
  • You can also do this:

    $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:computername)
    $regkey=$reg.OpenSubkey('SOFTWARE\Microsoft\Windows\CurrentVersion\OemInformation')
     'MODEL:{0}  Manufactured by:"{1}"' -f $regkey.GetValue('Model'),$regkey.GetValue('Manufacturer')
    


    ¯\_(ツ)_/¯

    Friday, May 16, 2014 8:08 PM
  • OEMInformation is a key - not a value:

    Heh. That certainly changes things.

    I should look at these things before posting I guess.


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    Friday, May 16, 2014 8:11 PM
  • OEMInformation is a key - not a value:

    Heh. That certainly changes things.

    I should look at these things before posting I guess.


    Don't retire TechNet! - (Don't give up yet - 12,830+ strong and growing)

    It also helps that I have seen the question before.

    This is one problem for people who do not know technology and just copy script and change them. It is always a surprosise when the changes don't work.  They ae stuck and do not know how to figure out why.

    The real issue here is a user that does not realize that most new machines do not allow remote registry access. Vista and later disable it by default.

    For this using WMI would be much easier.

    Computer (C:\temp\PCs.csv) | select name, Manufacturer



    ¯\_(ツ)_/¯

    Friday, May 16, 2014 8:20 PM
  • I really appreciate everyone's time and effort in guiding me towards my goal. I never claim to be a powershell expert and believe me this script is not going to get me a raise much less I will claim me as my own. I took Java and C++ back in college barely passing both. I knew then scripting was not my area. My only goal here is to get rid of my org's old Image. 
    After a week of trying I am still not able to output it to a CSV file it only shows on the command prompt screen. Any suggestions? 





    $strMachineName = import-csv C:\temp\PCS.csv
    foreach ($line in $strMachineName)
    {
        try {
            $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:computername)
    $regkey=$reg.OpenSubkey('SOFTWARE\Microsoft\Windows\CurrentVersion\OemInformation')
     'MODEL:{0}  Manufactured by:"{1}"' -f $regkey.GetValue('Model'),$regkey.GetValue('Manufacturer')

            ('"{0}","{1}"' -f $line.computer, $OEMInformation) | out-file C:\temp\PCs-out.csv -append -encoding ascii
        } catch {
            ('"{0}","{1}"' -f $line.computer, $_) | out-file C:\temp\PCs-err.csv -append -encoding ascii
        }
    }
    Tuesday, May 27, 2014 3:05 PM
  • You are now asking a new question.  This thread should have been marked as answered.

    If you are having issues with CSV output you should spend time searching for what others have done.  It is one of the most common things in PowerShell.  YOu could also use the "Learning" sources.

    Playing like you are not competent to do this is not a very professional response.  It will lnot likely get you any sympathy.

    Here is a stock solution.  If you cannot understand it or how to use it  please review the resources and post any new questions in a new thread.

    $strMachineName = import-csv C:\temp\PCS.csv
    $results=foreach ($line in $strMachineName) {
         try {
             $reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:computername)
             $regkey=$reg.OpenSubkey('SOFTWARE\Microsoft\Windows\CurrentVersion\OemInformation')
              New-Object PsObject -Property @{
                                                                              Model=$regkey.GetValue('Model')
                                                                              Manufacturer=$regkey.GetValue('Manufacturer')
                                                                             }
         }
         Catch{
               Write-Host "$_"  -fore red
         }
     }
    $results|Export-Csv csvfile.csv -NoType
    


    ¯\_(ツ)_/¯

    Tuesday, May 27, 2014 3:43 PM
  • Please look carefully at the code you are trying to use.  You need to think about what you are doing. Ther are obvious issues with what you are asking for.  You are also not attempting to understand the solution.

    In PowerShell there is help and it has many examples.  Always start by reviewing the help. Look at examples in the repository.  Read the "learning" resources.


    ¯\_(ツ)_/¯

    • Marked as answer by Newbie 1 Tuesday, May 27, 2014 4:23 PM
    Tuesday, May 27, 2014 3:46 PM