Solved

how can i pass credentials to this script? - powershell

Posted on 2014-09-16
4
588 Views
Last Modified: 2014-09-21
how can I pass credentials to this script so I can login to each pc and parse the registry?
$array =@()
$keyname = 'SOFTWARE\\Microsoft\\Internet Explorer'
$computernames = Get-Content C:\Computer.csv
foreach ($server in $computernames)
{
$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $server)
$key = $reg.OpenSubkey($keyname)
$value = $key.GetValue('Version')
 $obj = New-Object PSObject
        
        $obj | Add-Member -MemberType NoteProperty -Name "ComputerName" -Value $server
        
        $obj | Add-Member -MemberType NoteProperty -Name "IEVersion" -Value $value

        $array += $obj 


}

$array | select ComputerName,IEVersion | export-csv IE_Version.csv

Open in new window

0
Comment
Question by:bbimis
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 3

Assisted Solution

by:Phil Bossman
Phil Bossman earned 300 total points
ID: 40326657
1 Are you expecting to "login" to each computer in [computer.csv] with independent credentials or are you going to use the same credentials for all connections?
2. The same code you provided only works, if RemoteRegistry has been enabled on the remote side and the credentials used to run the script has "admin" access to the remote registry.  OpenRemoteBaseKey will use the implicit credentials of the running user, establishing the connection using IPC

If you need to prompt and use single creds, then you'll need to define those outside the foreach loop.  Also you'll need to change the connection method to the remote registry, possibly use WMI or some other method that allows you to supply credentials, as [Microsoft.Win32.RegistryKey] only uses the invoker's credentials.
0
 

Accepted Solution

by:
bbimis earned 0 total points
ID: 40326728
I opted for a different method by simply psexec'ing a bat file
thanks for your help though. I will give partial credit for your time.
0
 
LVL 3

Expert Comment

by:Phil Bossman
ID: 40327113
Glad to hear you got this resolved, which ever method you used
0
 

Author Closing Comment

by:bbimis
ID: 40335082
found different method
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question