UpdateImmutableID: Difference between revisions

From UmsWiki
Jump to navigation Jump to search
Rum (talk | contribs)
No edit summary
Rum (talk | contribs)
No edit summary
Line 1: Line 1:
<nowiki>
  $usersTable = New-Object system.Data.DataTable “UsersTable”
 
  $column1 = New-Object System.Data.DataColumn userPrincipalName,
<code></nowiki>
  ([String])
 
  $column2 = New-Object System.Data.DataColumn immutableId,
$usersTable = New-Object system.Data.DataTable “UsersTable”
  ([String])
 
  $usersTable.Columns.Add($column1)
$column1 = New-Object System.Data.DataColumn userPrincipalName,
  $usersTable.Columns.Add($column2)
 
  $users=Import-Csv -Path users.csv -Header “userSamAccountName”
([String])
  foreach($user in $users)
 
  {
$column2 = New-Object System.Data.DataColumn immutableId,
  $adUser = Get-ADUser -Identity $user.userSamAccountName
 
  $adUserGuid = $adUser.ObjectGUID
([String])
  $byteArray = $adUserGuid.ToByteArray()
 
  $immutableId = “”
$usersTable.Columns.Add($column1)
  $immutableId = [system.convert]::ToBase64String($byteArray)
 
  $row = $usersTable.NewRow()
$usersTable.Columns.Add($column2)
  $row.userPrincipalName = $adUser.userPrincipalName
 
  $row.immutableId = $immutableId
$users=Import-Csv -Path users.csv -Header “userSamAccountName”
  $usersTable.Rows.Add($row)
 
  }
foreach($user in $users)
  $usersTable | Export-Csv “c:\Users\Inlogic\UserExportIds.csv”
 
{
 
$adUser = Get-ADUser -Identity $user.userSamAccountName
 
$adUserGuid = $adUser.ObjectGUID
 
$byteArray = $adUserGuid.ToByteArray()
 
$immutableId = “”
 
$immutableId = [system.convert]::ToBase64String($byteArray)
 
$row = $usersTable.NewRow()
 
$row.userPrincipalName = $adUser.userPrincipalName
 
$row.immutableId = $immutableId
 
$usersTable.Rows.Add($row)
 
}
 
$usersTable | Export-Csv “c:\Users\Inlogic\UserExportIds.csv”
 
 
<nowiki></code></nowiki>

Revision as of 12:39, 24 June 2019

 $usersTable = New-Object system.Data.DataTable “UsersTable”
 $column1 = New-Object System.Data.DataColumn userPrincipalName,
 ([String])
 $column2 = New-Object System.Data.DataColumn immutableId,
 ([String])
 $usersTable.Columns.Add($column1)
 $usersTable.Columns.Add($column2)
 $users=Import-Csv -Path users.csv -Header “userSamAccountName”
 foreach($user in $users)
 {
 $adUser = Get-ADUser -Identity $user.userSamAccountName
 $adUserGuid = $adUser.ObjectGUID
 $byteArray = $adUserGuid.ToByteArray()
 $immutableId = “”
 $immutableId = [system.convert]::ToBase64String($byteArray)
 $row = $usersTable.NewRow()
 $row.userPrincipalName = $adUser.userPrincipalName
 $row.immutableId = $immutableId
 $usersTable.Rows.Add($row)
 }
 $usersTable | Export-Csv “c:\Users\Inlogic\UserExportIds.csv”