How to have PowerShell to not truncate in the table for logon hours?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
cgjackson@yahoo.com
Posts: 7
Joined: Wed Mar 01, 2017 12:54 pm

How to have PowerShell to not truncate in the table for logon hours?

Post by cgjackson@yahoo.com » Sat Apr 15, 2017 8:42 am

I have tried several different ways, but it truncates the table:

$User = Get-ADUser -Identity $name -Server $DC1 -Properties SamAccountName,LogonHours

$User.LogonHours



(Get-ADUser -Identity $name -Server $DC1 -Properties SamAccountName,LogonHours).LogonHours



Get-Aduser -Identity $name -Property * -Server $DC1 | Select SamAccountName, logonhours

SamAccountName logonhours

-------------- ----------

spect14 {0, 0, 0, 0...}

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to have PowerShell to not truncate in the table for logon hours?

Post by jvierra » Sat Apr 15, 2017 10:38 am

That is because it is an array and not a string.


Get-Aduser -Identity $name -Property * -Server $DC1 | Select -expand logonhours

User avatar
cgjackson@yahoo.com
Posts: 7
Joined: Wed Mar 01, 2017 12:54 pm

Re: How to have PowerShell to not truncate in the table for logon hours?

Post by cgjackson@yahoo.com » Wed Apr 19, 2017 1:44 pm

Thanks. That does it. Is there any way to make it not put one at a time.
Is there way to display 0 0 0 0 or whatever the return is thanks again.
Here is the output:
After set MCADDNSTDC03
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to have PowerShell to not truncate in the table for logon hours?

Post by jvierra » Wed Apr 19, 2017 1:48 pm

Get-Aduser -Identity $name -Property * -Server $DC1 | Select -expand logonhours | %{$_ -join ','}

User avatar
cgjackson@yahoo.com
Posts: 7
Joined: Wed Mar 01, 2017 12:54 pm

Re: How to have PowerShell to not truncate in the table for logon hours?

Post by cgjackson@yahoo.com » Tue Apr 25, 2017 1:13 pm

Get-ADUser -Identity $name -Credential $cred -Server $DC8 -Property *| Select -expand logonhours | %{$_ -join ','}
That gives me the same results.
After set MCADDNSTNA01
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

User avatar
jvierra
Posts: 13793
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: How to have PowerShell to not truncate in the table for logon hours?

Post by jvierra » Tue Apr 25, 2017 1:22 pm

Code: Select all

PS C:\scripts> $user = get-aduser jsmith -prop logonhours|select logonhours
PS C:\scripts> $user.logonhours -join '|'
32|0|0|32|0|0|32|0|0|32|0|0|32|0|0|32|0|0|32|0|0
PS C:\scripts>

Locked