How about this?
Select-Object @{Name="userName";Expression={$_.SamAccountName.Trim()}}, etc.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I have some samAccountNames that when selected have a space at the end in AD, I have tried every which way to use Trim to get ride of it in the statement but i always get an error. What is the correct way to use it in this statement.
This is the main statment
#Select the objects from the Get-ADuser and put in an array for use later
$dvaacctArray = $dvamailboxAccounts | select @{Name="userName";Expression={$_.SamAccountName}}, @{Name="address";Expression={"my information"}},
@{Name="safeName";Expression={'my info'}},@{Name="platformId";Expression={'My Info'}},
@{Name="secret";Expression={'12345678'}}
Tried these
select Trim(@{Name="userName";Expression={$_.SamAccountName}}),
Error = A positional parameter cannot be found that accepts argument 'System.Object[]
select @{Name="userName";Expression=Trim({$_.SamAccountName}}),
Error = Unexpected token in expression or statement
select @{Name="userName";Expression={Trim($_.SamAccountName)}},
Error = Cannot convert 'Microsoft.ActiveDirectory.Management.ADPropertyValueCollection' to the type 'System.String' required by parameter 'Server'. Specified method is not supported
At a loss as how to make sure no spaces happen at end as if they are in the name it fails later on in my script when trying to load it into a specialty database.
How about this?
Select-Object @{Name="userName";Expression={$_.SamAccountName.Trim()}}, etc.