SketchMaster
Diamond Member
Trying to help teammate migrate data to a new app by digging through an exported XML file. We need two bits of info:
-Friendly name (UserRole Name)
-Fully Qualified Domain name (User UserName)
Here is an example of the XML:
(FQDNs are mangled on purpose in this example)
It's easy enough to pull out the list of friendly names:
Or the list of FQDNs:
But say I wanted to do something like this...
Pseudo code:
I've tried every combination of loop commands I know of, but I can't get it to go through the list front top to bottom and pull out the info two by two without mixing up the data. Any ideas on how to do this?
-Friendly name (UserRole Name)
-Fully Qualified Domain name (User UserName)
Here is an example of the XML:
Code:
<?xml version="1.0" encoding="utf-8"?>
<UserRoles xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<UserRole Name="My USER 1" DisplayName="My USER 1" Description="" Profile="Operator">
<User UserName="DOMAIN\MyUSER 1" />
</UserRole>
<UserRole Name="My USER 2" DisplayName="My USER 2" Description="" Profile="ReadOnlyOperator">
<User UserName="DOMAIN\MyUSER2" />
</UserRole>
<UserRole Name="My USER 3" DisplayName="My USER 3"
<UserRole Name="My USER 3" DisplayName="My USER 3" Description="" Profile="Operator">
<User UserName="DOMAIN\My.USER 3" />
(FQDNs are mangled on purpose in this example)
It's easy enough to pull out the list of friendly names:
Code:
[xml]$XML = Get-Content C:\Users\SketchMaster\Desktop\userroles.xml
$names = ($xml.UserRoles.ChildNodes.name)
ForEach ($name in $names)
{Write-host "this is $name"}
Or the list of FQDNs:
Code:
[xml]$XML = Get-Content C:\Users\SketchMaster\Desktop\userroles.xml
$Users = $users = ($xml.UserRoles.ChildNodes.user.username)
ForEach ($user in $users)
{Write-host "this is $user"}
But say I wanted to do something like this...
Pseudo code:
Code:
#get data
[xml]$XML = Get-Content C:\Users\SketchMaster\Desktop\userroles.xml
$Users = ($xml.UserRoles.ChildNodes.user.username)
$Names = ($xml.UserRoles.ChildNodes.name)
#Start command
Foreach (UserRole)
{
#-Name = Friendly name | -User = FQDNs
Add-UserRole -Name '$Name' -Operator -User '$User'
}
I've tried every combination of loop commands I know of, but I can't get it to go through the list front top to bottom and pull out the info two by two without mixing up the data. Any ideas on how to do this?
Last edited: