Solved

how can i pass credentials to this script? - powershell

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

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 …
A brief introduction to what I consider to be the best editor for PowerShell.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

821 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