Solved

how can i pass credentials to this script? - powershell

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

822 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