|
This is useful for collecting contacts from an old Windows 8 People app that does not allow exporting.
Copy to Clipboard
# Used to import data from XML .appcontent.ms files
# This CSVHeader format is taken from a Google Contacts Export
$CSVHeader = "First Name,Middle Name,Last Name,Phonetic First Name,Phonetic Middle Name,Phonetic Last Name,Name Prefix,Name Suffix,Nickname,File As,Organization Name,Organization Title,Organization Department,Birthday,Notes,Photo,Labels,E-mail 1 - Label,E-mail 1 - Value,E-mail 2 - Label,E-mail 2 - Value,E-mail 3 - Label,E-mail 3 - Value,E-mail 4 - Label,E-mail 4 - Value,E-mail 5 - Label,E-mail 5 - Value,Phone 1 - Label,Phone 1 - Value,Phone 2 - Label,Phone 2 - Value,Phone 3 - Label,Phone 3 - Value,Phone 4 - Label,Phone 4 - Value,Phone 5 - Label,Phone 5 - Value,Phone 6 - Label,Phone 6 - Value,Phone 7 - Label,Phone 7 - Value,Phone 8 - Label,Phone 8 - Value,Phone 9 - Label,Phone 9 - Value,Address 1 - Label,Address 1 - Formatted,Address 1 - Street,Address 1 - City,Address 1 - PO Box,Address 1 - Region,Address 1 - Postal Code,Address 1 - Country,Address 1 - Extended Address,Address 2 - Label,Address 2 - Formatted,Address 2 - Street,Address 2 - City,Address 2 - PO Box,Address 2 - Region,Address 2 - Postal Code,Address 2 - Country,Address 2 - Extended Address,Address 3 - Label,Address 3 - Formatted,Address 3 - Street,Address 3 - City,Address 3 - PO Box,Address 3 - Region,Address 3 - Postal Code,Address 3 - Country,Address 3 - Extended Address,Website 1 - Label,Website 1 - Value,Website 2 - Label,Website 2 - Value"
$ArrCSVHeader = $CSVHeader -split ','
$ArrOut = @()
function Add-Link($In, $Out){ # In is the field name in the appcontent.ms file, Out is the field name in the contacts export file
$Linker.Item($In) = $Out
$LinkerRev.Item($Out) = $In
}
$Linker = @{}
$LinkerRev = @{}
$Contacts = @()
Add-Link -In 'System.Contact.FirstName' -Out 'First Name'
Add-Link -In 'System.Contact.LastName' -Out 'Last Name'
Add-Link -In 'System.Contact.HomeAddress1Locality' -Out 'Address 1 - City'
Add-Link -In 'System.Contact.HomeAddress1PostalCode' -Out 'Address 1 - Postal Code'
Add-Link -In 'System.Contact.HomeAddress1Region' -Out 'Address 1 - Region'
Add-Link -In 'System.Contact.HomeAddress1Street' -Out 'Address 1 - Street'
Add-Link -In 'System.Contact.HomeEmailAddresses' -Out 'E-mail 1 - Value'
Add-Link -In 'System.Contact.OtherEmailAddresses' -Out 'E-mail 2 - Value'
Add-Link -In 'System.Contact.BusinessEmailAddresses' -Out 'E-mail 3 - Value'
Add-Link -In 'System.Contact.DisplayMobilePhoneNumbers' -Out 'Phone 1 - Value'
Add-Link -In 'System.Contact.DisplayHomePhoneNumbers' -Out 'Phone 2 - Value'
Add-Link -In 'System.Contact.DisplayBusinessPhoneNumbers' -Out 'Phone 3 - Value'
function Import-Folder($Path, $ExportPath){
$Files = Get-ChildItem -Path $Path
foreach ( $File in $Files) {
Import-File $File.FullName
}
if ( $ExportPath.length -gt 5 ){
Export-Contacts -Path $ExportPath
Write-Host "Contacts exported to: $($ExportPath)"
}
}
function Import-File($Path){
Write-Host "Importing file $($Path)"
$Contact = @{}
foreach ($Name in $ArrCSVHeader ){
$Contact.Item($Name) = ""
}
[xml]$xmlDoc = Get-Content -Raw $Path
foreach ($node in $xmlDoc.ContactAppData.Properties.AdditionalProperties.ChildNodes) {
if ( $Linker.ContainsKey($node.key) ){
$Contact.Item($Linker.Item($node.key)) = $node.Value
}
}
$Script:Contacts += $Contact
#$Contact
}
function Export-Contacts($Path){
# Convert hashtables to PSCustomObjects to allow CSV export
$arrout = @()
foreach ($Contact in $Script:Contacts ){
$arrout += [pscustomobject]$contact
}
$arrout | Export-Csv -Path $Path -NoTypeInformation
}
Import-Folder -Path "C:\Users\Path\To\Files" -ExportPath "C:\Users\Output\Contacts.csv"
|