tkasmir
February 25, 2019, 7:15am
1
I catch many more properties than these two, but showing only these two for brevity.
The report works. But the ControllerDNSName is not getting truncated. My usage of -Width 8 is being ignored.
$Properties = (Get-BrokerSession -AdminAddress xxxxxxxxx | Select UserFullName, ControllerDNSName| WHERE {$_. UserFullName -eq $User} )
$STR = $Properties.ControllerDNSName
$DCstr = Out-String -InputObject $STR -Width 8 #This is being ignored
New-Object -Typename PSObject -property @{
‘User’ = $Properties.UserFullName
‘DC’ = $DCstr
} | Select-Object ‘User’, ‘DC’
}
$Results | ConvertTo-HTML | Out-file $Report
I looked up WIDTH in this context and read that “The Width parameter applies only to objects that are being formatted.”
Is HTML output not a format? Or am I misinterpreting the word format in this context?
Olaf
February 25, 2019, 8:03am
2
Could you please format your code as code? Thanks.
You might add the results you get at the moment and the results you’d like to get actually. (Or samples illustrating the results)
js2010
February 25, 2019, 8:56am
3
Hmmm, the width option of out-string seems meaningless…
PS C:\users\me> '123456789' | Out-String -Width 5
123456789
Olaf
February 25, 2019, 9:12am
4
You might need something like this:
‘123456789’.substring(0,5)
or this:
‘123456789’[0…4] -join ‘’
Not familiar with the cmdlet, but based on the documentation , there is a filter for UserDisplayName. Additionally, you can use calculated expressions to do the rest, something like this:
$results = Get-BrokerSession -AdminAddress xxxxxxxxx -UserFullName $user |
Select @{Name='User';Expression={$_.UserFullName}},
@{Name='ControllerDNSName';Expression={$_.ControllerDNSName}},
@{Name='DC';Expression={$_.ControllerDNSName.SubString(0,8)}}
js2010
February 25, 2019, 10:07am
6
I guess “out-string -width” can only be used like this, on an object, not a string:
PS C:\users\me> [pscustomobject]@{name='1234567890'} | Out-String -Width 8
name
----
12345...
PS C:\users\me> '123456789' | Out-String -Width 5
123456789
PS C:\users\me> [pscustomobject]@{name1='1234567890';name2='1234567890';name3='1234567890';name4='1234567890';
name5='1234567890'} | out-string -Width 17
name1 : 123456789
0
name2 : 123456789
0
name3 : 123456789
0
name4 : 123456789
0
name5 : 123456789
0
See if you can get the results as a list using …
$Results | Format-List -Force
… to determine if the built-in formatters will auto-expand all that is there, just as a sanity check.
tkasmir
February 26, 2019, 2:18pm
8
This is yielding some good early results. Thanks!
Yep. This SubString approach really does the trick. Plus it’s a new way (to me) for how to write SELECT statements. I like this.