Skip to content

Instantly share code, notes, and snippets.

@joerodgers
Last active November 12, 2020 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joerodgers/85b9f5a48804718ea850eee91c7bd773 to your computer and use it in GitHub Desktop.
Save joerodgers/85b9f5a48804718ea850eee91c7bd773 to your computer and use it in GitHub Desktop.
Generates the metalogix xml file using the raw LoginName and Email values for users stored in the target SharePoint site.
Add-PSSnapin Microsoft.SharePoint.PowerShell
function ConvertTo-MetalogixUserMappingXml
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][object[]]$Mapping
)
begin
{
$xml = New-Object System.Text.StringBuilder
$xml.AppendLine( "<Mappings>" ) | Out-Null
}
process
{
foreach( $map in $Mapping )
{
$xml.AppendLine( "<Mapping Source=`"$($Mapping.Source)`" Target=`"$($Mapping.Target)`" />" ) | Out-Null
}
}
end
{
$xml.AppendLine( "</Mappings>" ) | Out-Null
return $xml.ToString()
}
}
Get-SPSite -Identity "https://sharepoint.2016.contoso.com/sites/teamsite" |
SELECT -ExpandProperty RootWeb |
SELECT -ExpandProperty SiteUsers | ? { -not [string]::IsNullOrEmpty($_.Email) } |
SELECT @{Name="Source"; E={ $_.UserLogin}}, @{Name="Target"; E={$_.Email}} |
ConvertTo-MetalogixUserMappingXml |
Set-Content -Encoding UTF8 -Path "MappingFile_$(Get-Date -Format FileDateTime).xml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment