The below function is supposed to add the the passed parameters, and values, to a hashtable for later use when setting the actual properties but. . . for a reason I can't understand, the hashtable is only displayed once, with just one set of properties.
I'm trying to have it splat all the values passed for each user, but it only does it for one.
Function Change-DRAUserProperty {
Param (
[Parameter(Mandatory=$true,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true)]
[string[]]$UserName,
$Company,
$Department,
$DisplayName,
$Name,
$O,
$PhysicalDeliveryOfficeName,
$TelephoneNumber,
$Title
)
Begin
{
$OrgBoxOu = "*OU=XX, DC=XX"
$Parameters = $PSBoundParameters
$Properties = @{}
}
Process
{
foreach ($User in $UserName)
{
try {
$SelectedUser = $User
if ($SelectedUser) {
$Parameters.GetEnumerator() | Where-Object Key -ne 'UserName' |
ForEach-Object -Process `
{
if ($_.Key -eq 'DisplayName' -and $SelectedUser.DistinguishedName -notlike $OrgBoxOu) {
$Properties.Add('FirstNamePreferred', $_.Value)
}
$Properties.Add($_.Key, $_.Value)
}
$Properties
#Set-DRAUser -Identifier $SelectedUser.DistinguishedName -Properties $Properties @DRA_Server_Splat -ErrorAction Stop
}
else {
Write-Host -Object "No valid member selected!"
}
}
catch {
Write-Host -Object "$($_.Exception.Messge)" -ForegroundColor Red -BackgroundColor Black
continue
}
}
}
End { }
}
Using the command line arguments: Change-DRAUserProperty -UserName Abe, Abe2, Abe3 -Company SSC -Department USSF
. . .only displays:
Name Value
---- -----
Department USSF
Company SSC
Instead of one per user passed (what the results should be):
Name Value
---- -----
Department USSF
Company SSC
Name Value
---- -----
Department USSF
Company SSC
Name Value
---- -----
Department USSF
Company SSC
No too sure what I may be doing wrong, may I have someone else take a look over and point out my mistakes?
Am I going crazy guys?