header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Remote Authentication
Last Post 04 Feb 2008 01:19 PM by smurawski. 5 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
craig_sharpeUser is Offline
New Member
New Member
Posts:2

--
01 Feb 2008 03:26 PM  

I'm wanting to convert a simple script from VBScript into powershell, basically I need to connect to a remote machine using alternative credentials and obtain some information from it..

The VBScript code is as follows:
Set objSWbemLocator =  CreateObject("WbemScripting.SWbemLocator";)
Set objSWbemServices =  objSWbemLocator.ConnectServer(strComputer,  "root\cimv2", strUser, strPassword)


but the powershell equivalent doesn't appear to work:
$objSWbemLocator = new-object -com "WbemScripting.SWbemLocator"
$test = $objSWbemLocator.ConnectServer(strComputer, "root\CIMV2", strUser, strPassword)

I just keep getting an access denied message, It works ok if I try to use the local machine and don't specify the credentials.. I've also tried passing the credentials directly from the get-credential cmdlet.

 

Any help on this would be much appreciated!

KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:144

--
01 Feb 2008 04:45 PM  
Craig;

This should get you started:

$cred = get-credential mydomain\administrator
gwmi –namespace "root\cimv2" –list –credential $cred –computer strComputer
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:144

--
01 Feb 2008 04:48 PM  
I shouldn't have used the alias there.

gwmi = Get-WmiObject

So
$cred = get-credential mydomain\administrator
Get-WmiObject –namespace "root\cimv2" –list –credential $cred –computer strComputer
KarlMitschkeUser is Offline
Basic Member
Basic Member
Posts:144

--
01 Feb 2008 04:50 PM  
Well, I should drink more coffee

strComputer is useless in powershell as well. $strComputer is the proper variable usage
craig_sharpeUser is Offline
New Member
New Member
Posts:2

--
04 Feb 2008 09:56 AM  

Hi Karl,

Thanks for your quick response, I've been playing with this over the weekend and I'm still having problems..  Firstly, my main issue with your suggestion is that the script needs to be automated and therefore it is not possible to use get-credential as this requires user input.  however I can't get it to work properly with that method either.

I'm tring the following ways:

$cred = get-credential MyDomain\Administrator
$test = Get-WmiObject -namespace "root\default" -class "StdRegProv" -credential $cred -computer $strComputer

and also

$obj = new-object -com "WbemScripting.SWbemLocator"
$conn=$obj.ConnectServer($strComputer, "root\default", $strUserName, $strPassword)
$test=$conn.Get("StdRegProv";)

Both ways seem to work, but then when I try to write out $test OR pipe $test to get-member, it is empty

$test|gm
Get-Member : No object has been specified to get-member.
At line:1 char:5
+ $test|gm <<<<

Any ideas how I can query a remote registry key in an automated fashion using powershell, as I'm stuck!

Thanks in advance..

Craig

smurawskiUser is Offline
New Member
New Member
Posts:45

--
04 Feb 2008 01:19 PM  
Craig,

I was able to get both WMI ways to work, and was getting results from $test | gm. And it doesn't appear to be a permissions problem, because you most likely would have gotten an Exception while trying to connect to the registry provider.

If you don't mind skipping WMI and your user account has the necessary privileges, you can access the remote registry via the .NET Framework.

$rootkey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine',$computername)

From their you can explore to where you need using the properties and methods on the returned object.

From briefly playing around with it, the "OpenSubKey" method, the "GetSubkeyNames" method, the "GetValueNames" method, and the "GetValue" method will all come in handy.

You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer