Solved

how can i pass credentials to this script? - powershell

Posted on 2014-09-16
4
597 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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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