gerhardub
asked on
Formating Table output so that it doesn't truncate columns
Ok,
So I have a PowerShell script what now works pretty well to dump a basic weekly audit.
The big issue at this point is that it mails a text file that tells me:
- Accounts created this week
- Groups modified this week
- Users not logged on in 30 days
- Users not logged on in 30-60 days
- Users not logged on in over 90 days
- Users with active accounts that haven't logged on ever
To create the output, I'm doing this:
When I run the powershell script manually, I get a non-truncated output. When I run it as a timer job, I get:
Name DN samaccountname
---- -- --------------
John Smith CN=John Smith,OU=Use... jsmith
I've looked at the format-table options, and I don't really see one that will obviously fix my problem.
How to I fix this, or put it in a format that will allow me to email it without loosing critical information?
My email command is this:
So I have a PowerShell script what now works pretty well to dump a basic weekly audit.
The big issue at this point is that it mails a text file that tells me:
- Accounts created this week
- Groups modified this week
- Users not logged on in 30 days
- Users not logged on in 30-60 days
- Users not logged on in over 90 days
- Users with active accounts that haven't logged on ever
To create the output, I'm doing this:
$OutputfilePath = "C:\ADUserAudit-"+([datetime]::Now).tostring("yyyyMMdd")+".txt"
$30DaysTable = ($30Days | format-table)
$60DaysTable = ($60Days | format-table)
$90DaysTable = ($90Days | format-table)
# Get users that have never logged in, but use Windows AD Powershell cmdlets as it should look at all domain controllers. Not restricted to OU:
$NeverBeenKissed = get-aduser -f {-not ( lastlogontimestamp -like "*") -and (enabled -eq $true)} | select samaccountname,name,distinguishedname
$NeverBeenKissedTable = $NeverBeenKissed | format-table
# Write to a file
Out-File $OutputfilePath
Add-Content -Path $OutputfilePath "Users Created in the Last Week:"
Add-Content -Path $OutputfilePath " "
$UsersCreatedLastWeekTable | Out-File $OutputfilePath -append
Add-Content -Path $OutputfilePath "Groups Modified in the Last Week:"
Add-Content -Path $OutputfilePath " "
$GroupsModifiedLastWeekTable | Out-File $OutputfilePath -append
Add-Content -Path $OutputfilePath "Users not logged in for 30 days:"
Add-Content -Path $OutputfilePath " "
$30DaysTable | Out-File $OutputfilePath -append
Add-Content -Path $OutputfilePath "Users not logged in for 60-90 days:"
Add-Content -Path $OutputfilePath " "
$60DaysTable | Out-File $OutputfilePath -append
Add-Content -Path $OutputfilePath "Users not logged in for over 90 days:"
Add-Content -Path $OutputfilePath " "
$90DaysTable | Out-File $OutputfilePath -append
Add-Content -Path $OutputfilePath "Users who have NEVER logged in!:"
Add-Content -Path $OutputfilePath " "
$NeverBeenKissedTable | Out-File $OutputfilePath -append
When I run the powershell script manually, I get a non-truncated output. When I run it as a timer job, I get:
Name DN samaccountname
---- -- --------------
John Smith CN=John Smith,OU=Use... jsmith
I've looked at the format-table options, and I don't really see one that will obviously fix my problem.
How to I fix this, or put it in a format that will allow me to email it without loosing critical information?
My email command is this:
Send-MailMessage -To "group@company.com” -Subject “User Audit 7/7/30/60/90” -From “PowerShellAudit@company.com” -Body “Current weekly AD User Audit is attached. Note: You need to look at this file full screen.” -Priority High -SmtpServer $smtpServer -Attachments $OutputfilePath
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This solution prevents -wrap and it's readability issues, and the fact the -autosize only works within the confines of the current shell environment (which is 120 characters when running as a Windows timer job).
Or
use -Wrap option