lundi 26 janvier 2015

Get-SPUser returns additional blank lines. How do I remove them when reading into array?



I am attempting to get a list of users for the site that are part of a specific domain. The end result will be putting them in a SQL DB, which is fine; I just need to get the array clean.


I am not sure which format I want to use yet.



Get-SPUser -web http://ift.tt/1Da0qpD -Limit ALL | Where-Object {$_.UserLogin -like "*DOMAIN\*"} | Format-Table DisplayName, Email -HideTableHeaders

Get-SPUser -web http://ift.tt/1Da0qpD -Limit ALL | Where-Object {$_.UserLogin -like "*DOMAIN\*"} | Format-List DisplayName, Email


At this point, the Format-Table and Format-List cmdlets are including extra lines. One quick way to view that it indeed looks at them as items, is to get a count.


For instance, if I set it to a variable to get a count.



$a = Get-SPUser -web http://ift.tt/1Da0qpD -Limit ALL | Where-Object {$_.UserLogin -like "*DOMAIN\*"} | Format-Table DisplayName, Email -HideTableHeaders
$a.count


The result will have an additional 4 lines, so I will need to account for that.



$a.count - 4


There must be a clean way to get these values, as even looping through the array still returns the blank lines.



Foreach ($i in $a){$i}


Any help is appreciated. Thanks.








0 commentaires:

Enregistrer un commentaire