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)
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
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
Thank you for the explanation and the corrected file.
Tested and fully working.
Cheers,
Darren.
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 ...
The script only exports the roles.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.