Solved

how can i pass credentials to this script? - powershell

Posted on 2014-09-16
4
535 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
Comment Utility
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
Comment Utility
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
Comment Utility
Glad to hear you got this resolved, which ever method you used
0
 

Author Closing Comment

by:bbimis
Comment Utility
found different method
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now