'Associate Google accounts with existing Windows profiles

We are looking to setup Google Credential Provider for Windows (GCPW) as we are mostly Google in our environment. After installing the application if someone signs in a new profile is created. To Associate Google accounts with existing Windows profiles a registry key must be made with the users SID and an email value of the user.

The issue I am having is creating the email value with the profile name for each users SID. You will see I am trying to get the username from "ProfileImagePath" take out the path and keep the profile name. Then add that to the email value for each matching SID key that is created for each user that has signed into the machine previously.

Not sure what I am doing wrong. Any guidance or direction would be greatly appreciated.

Error:

Method invocation failed because [System.Management.Automation.PSCustomObject] does not contain a method named 'ProfileImagePath'.
At C:\Temp\Untitled3.ps1:18 char:98
+ ... -Name 'email' -Value $($user.ProfileImagePath()+"@domain.org")
+                            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ProfileImagePath:String) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound
 
Set-ItemProperty : Cannot find path 'HKLM:\Software\Google\GCPW\Users\@{PSChildName=S-1-5-21-<OMITTED>; ProfileImagePath=<OMITTED>}.PSChildName' because it does not exist.
At C:\Temp\Untitled3.ps1:18 char:1
+ Set-ItemProperty -Path HKLM:\Software\Google\GCPW\Users\$user.PSChild ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (HKLM:\Software\...ia}.PSChildName:String) [Set-ItemProperty], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.SetItemPropertyCommand

Code:

#### Export SID and profile path (for username) ####
$path = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-*'
$getInfo = Get-ItemProperty -Path $path | Select-Object -Property PSChildName, ProfileImagePath
$export = $getInfo | Export-Csv -Path C:\Temp\SID1.csv -NoTypeInformation

#### Remove "C:\Users\" in Export ####
$mod = Get-Content C:\Temp\SID1.csv
$mod | ForEach-Object { $_-replace 'C:\\Users\\', ""} | Set-Content "C:\Temp\SID1.csv"

#### Import the Export ####
$info = Import-Csv -Path C:\Temp\SID1.csv

#### Create SID key. Then add email value in SID key of user. ####
ForEach ($user in $info) {

New-Item -Path HKLM:\Software\Google\GCPW\Users -Name $user.PSChildName -Force

Set-ItemProperty -Path HKLM:\Software\Google\GCPW\Users\$user.PSChildName -Name 'email' -Value $($user.ProfileImagePath()+"@domain.org")

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source