Skip to content

Instantly share code, notes, and snippets.

@OlafD
Created September 16, 2020 12:40
Show Gist options
  • Save OlafD/2cb5e22712e75bce18f9a8dd1912f427 to your computer and use it in GitHub Desktop.
Save OlafD/2cb5e22712e75bce18f9a8dd1912f427 to your computer and use it in GitHub Desktop.
To be used with the output of the Get-PnPProvisioningTemplate cmdlet, this script will replace all mail addresses (user accounts) in the xml file of the output with one static mail address. This is useful, when also content (pages) need to be moved to another tenant.
param (
$InFile,
$OutFile,
$MailDomain,
$ReplaceWith
)
$regexFind = "\b[A-Z0-9._%+-]+@$MailDomain\b"
$inputContent = Get-Content $InFile
$lineCount = $inputContent.Length
$outputContent = $inputContent
for ($i = 0; $i -lt $lineCount; $i++)
{
if (($inputContent[$i] -match $regexFind) -eq $true)
{
$outputContent[$i] = $inputContent[$i] -replace $regexFind, $ReplaceWith
}
}
$outputContent | Out-File $OutFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment