Hi guys. I am trying to write a simple script to send me a monthly report on a couple of things. I’d like to keep it nice and simple and include the items I want reported back to me in one CSV report. I’m running the following commands:
$old= get-date
$oldtime= $old.AddMonths(-3)
Write-output “AD USERS”; get-aduser -filter {lastlogondate -lt $oldtime} |select name | ? {$_.distinguishedname -notlike “ou=service accounts”} | Move-ADObject -TargetPath ‘ou=service accounts,ou=users,ou=organization,dc=***,dc=local’ | Export-Csv C:\test.csv -NoTypeInformation
Write-Output “AD COMPUTERS” ; get-adcomputer -filter {lastlogondate -lt $oldtime} | select name | Export-Csv C:\test.csv -NoTypeInformation -Append -Force
Write-Output “DHCP INFO” ;Get-DhcpServerv4Statistics -ComputerName ctl01 | select TotalScopes, TotalAddresses, AddressesInUse,AddressesaAailable,PercentageInUse | Export-Csv c:\test.csv -NoTypeInformation -append -Force
The problem is that although the script runs and exports what I have requested in to the csv, the write-outputs that I have tried to include are Excluded from the report. So all the information is on top of each other instead of being separated by the Header that I want separating the different info I have collected. Can anyone advice on how I can change the script to include the write-output in my report to separate the info collected?