VMware Cloud Community
dawoo
Enthusiast
Enthusiast
Jump to solution

Get-XmlNode syntax works in one script but not another.

Hi.

I've extracted some script from two of the highly respected PowerCLI gurus, messers Alan Renouf & LucD.

I'm using the PowerGUI environment and find one script completes successfully and one doesn't. They perform different tasks but I'm keen to understand the syntax error I'm receiving.

Both contain the 4 lines:

function Get-XmlNode{

param ($path)

$global:vInventory.SelectNodes($path)

}

In my 1st script I receive the error "Method invocation failed because http://System.String doesn't contain a method names 'SelectNodes'.

In my 2nd script the same lines complete succesfully. I've used the Debug feature to trace the message and scripting halt too.

Script 1, Export vCenter permissions ready for the import script : From Alan Renouf

Script 2, vProfile dump of your hosts, virtual machines etc... : From LucD (the variable $entity will need to reflect a valid cluster name)

It seems to me the message is attempting to say "I don't have knowledge of the parameter you've supplied".

I've attached both scripts if anyone has a moment to review.

Many thanks,

Darren.

(@dawoo)

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
Tags (2)
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

The reaason you're having this problem with script 1 is because $global:vInventory doesn't contain a XML document but a string.

And the method SelectNodes is not known on a string.

Attached a corrected version of script 1.

The basic problem was this line

$global:vInventory = "<Inventory><Roles></Roles><Permissions></Permissions></Inventory>"

which should in fact be

$global:vInventory = [xml]"<Inventory><Roles></Roles><Permissions></Permissions></Inventory>"

Note how the string is 'cast' to an XML document !

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
LucD
Leadership
Leadership
Jump to solution

The reaason you're having this problem with script 1 is because $global:vInventory doesn't contain a XML document but a string.

And the method SelectNodes is not known on a string.

Attached a corrected version of script 1.

The basic problem was this line

$global:vInventory = "<Inventory><Roles></Roles><Permissions></Permissions></Inventory>"

which should in fact be

$global:vInventory = [xml]"<Inventory><Roles></Roles><Permissions></Permissions></Inventory>"

Note how the string is 'cast' to an XML document !

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
dawoo
Enthusiast
Enthusiast
Jump to solution

Thank you for the explanation and the corrected file.

Tested and fully working.

Cheers,

Darren.

10 Print "It's all about the Nerdknobs" , 20 GOTO http://blog.vmote.net/
Reply
0 Kudos
DennieTidwell
Enthusiast
Enthusiast
Jump to solution

Do these scripts replace all roles or do they just add roles? Should they work the same on vCenter 4.1?

I see the script pulls the present roles but I can't see if they are retained or replaced ...

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The script only exports the roles.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
DennieTidwell
Enthusiast
Enthusiast
Jump to solution

I have downloaded the new scripts from virtu-al and the ones in this thread.

I am stuck with this error regardless of which import script I attempt. It creates 95% of the roles with no issue, but leaves one out. I have re-exported and reviewed the xml with no errors found.

I am presently attempting to verify "$privIds" via SDK.

Any help?

[vSphere PowerCLI] Q:\psscripts> ./import-xml-roles-permissions.ps1
Exception calling "AddAuthorizationRole" with "2" argument(s): "A specified parameter was not correct.
privIds"
At Q:\psscripts\import-xml-roles-permissions.ps1:7 char:48
+         $roleId = $authMgr.AddAuthorizationRole <<<< ($name,$privIds)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

[vSphere PowerCLI] Q:\private drop\datadigitalglobe\psscripts>

Thank you.

Reply
0 Kudos