Friends,
I have a script that that works ok except that in two columns, the data is truncated.
This is the script:
Import-Module activeDirectory
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Get Office'
$msg = 'Enter MarinesOfficeID NUMBER'
$InputUser = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$user=$InputUser.trim()
$Number = $user
Get-ADUser -Filter "MarinesOfficeID -like $Number" -properties * |
select Samaccountname, Office, MarinesOfficeID, City, State| format-table
Here is the output, as you can see there are some truncations.
They like this format, one line per person.
Samaccountname Office MarainesOfficeID City State
Elizabeth.Miller ABCDE 123456 Kansas City KS
Jerry.Macaguire ABCDE 123456 Kansas City KS
Mary.Jordan ABCDE 123456 Kansas City KS
Charles.Saddle ABCDE 123456 Kansas City KS
Christopher.Gal... ABCDE 123456 Kansas City KS
Lamont.Jones COOLA 123456 St Louis MO
Jennifer.Peabody MOL... 123456 Jones Burro KS
Christopher.Bau... LO-... 123456 Kansas City KS
I would prefer not to use -Autosize because this produces very long lists, using -Autosize would delay the appearance of the data, they want the console to start rolling very quickly.
So I tried to control the width of the columns, but I cannot get it right. I would appreciate it if you would help fix this:
Import-Module activeDirectory
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Get Office'
$msg = 'Enter MarinesOfficeID NUMBER'
$InputUser = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
$user=$InputUser.trim()
$Number = $user
Get-ADUser -Filter "MarinesOfficeID -like $Number" -properties * |
select Samaccountname, Office, MarinesOfficeID, City, State, DistinguishedName
[pscustomobject] @{ SamAccountName='$_.SamAccountName'};
[pscustomobject] @{ Office=$_.Office;Width=10};
[pscustomobject] @{ MarinesOfficeID=$_.MarinesOfficeID};
[pscustomobject] @{ City=$_.City};
[pscustomobject] @{ State=$_.State};
[pscustomobject] @{ DistinguishedName=$_.DistinguishedName} |
format-Table
@{name='SamAccountName';expression={$_.SamAccountName;Width=24}},
@{name='Office';expression={$_.Office;Width=24 }},
@{name='MarinesOfficeID';expression={$_.MarinesOfficeID;Width=10}},
@{name='City';expression={$_.City;Width=15}},
@{name='State';expression={$_.State;Width=2}},
@{name='DistinguishedName';expression={$_.DistinguishedName;Width=34}}
Thanks in advance for you help on this, I have spent hours and hours on it.