$DocumentsPath = [Environment]::GetFolderPath("MyDocuments")
Copy-Item -Path "$InstallDirectory\Age of Mythology" -Destination "$DocumentsPath\My Games\Age of Mythology" -Recurse
# Bounds are accessible by $Display.Bounds.Width and $Display.Bounds.Height
$Display = Get-PrimaryDisplay
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Pattern '^xres=(.+)' -Substitution "xres=$($Display.Bounds.Width)" -FilePath "$InstallDirectory\startup\user.cfg"
Write-ReplaceContentInFile -Pattern '^yres=(.+)' -Substitution "yres=$($Display.Bounds.Height)" -FilePath "$InstallDirectory\startup\user.cfg"
$DocumentsPath = [Environment]::GetFolderPath("MyDocuments")
Remove-Item -Path "$DocumentsPath\My Games\Age of Mythology" -Force -Recurse
# Sanitize name as it will be used in a file name
$NewPlayerAlias = $NewPlayerAlias.Split([IO.Path]::GetInvalidFileNameChars()) -join '_'
$Guid = [Guid]::NewGuid().ToString().ToUpper()
$DocumentsPath = [Environment]::GetFolderPath("MyDocuments")
Copy-Item -Path "$InstallDirectory\Age of Mythology\Users\Default.prf" -Destination "$DocumentsPath\My Games\Age of Mythology\Users\$NewPlayerAlias.prf"
# Use regex to replace text within a file. Quotes are escaped by double quoting ("")
Write-ReplaceContentInFile -Pattern '<profilename>(.*)</profilename>' -Substitution "<profilename>$NewPlayerAlias</profilename>" -FilePath "$DocumentsPath\My Games\Age of Mythology\Users\$NewPlayerAlias.prf"
Write-ReplaceContentInFile -Pattern '<profilelanname>(.*)</profilelanname>' -Substitution "<profilelanname>$NewPlayerAlias</profilelanname>" -FilePath "$DocumentsPath\My Games\Age of Mythology\Users\$NewPlayerAlias.prf"
Write-ReplaceContentInFile -Pattern '<profileguid>(.*)</profileguid>' -Substitution "<profileguid>{$Guid}</profileguid>" -FilePath "$DocumentsPath\My Games\Age of Mythology\Users\$NewPlayerAlias.prf"
Write-ReplaceContentInFile -Pattern '^playerProfileName "(.+)"' -Substitution "playerProfileName ""$NewPlayerAlias""" -FilePath "$DocumentsPath\My Games\Age of Mythology\startup\persistent.cfg"
Write-ReplaceContentInFile -Pattern '^playerGUID "(.+)"' -Substitution "playerGUID ""{$Guid}""" -FilePath "$DocumentsPath\My Games\Age of Mythology\startup\persistent.cfg"
$NewPlayerAlias | Out-File -FilePath "$DocumentsPath\My Games\Age of Mythology\Users\LastProfile.txt"