Public/Invoke-ADAudit.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 |
function Invoke-ADAudit { #Prepare Workplace for script Execution $basePath=New-Workplace $reportGraphFolders = Get-ReportFolders -BasePath $basePath -GraphFoldersHashtable $graphFolders $reportFilePath = Join-Path -Path $basePath -ChildPath "report.docx" $logFilePath=Join-Path -Path $basePath -ChildPath "log.txt" New-InformationLog -LogPath $logFilePath -Message "Started to creating report" -Color GREEN $reportFile = New-WordDocument $reportFilePath Add-WordText -WordDocument $reportFile -Text "Active Directory Report" -FontSize 28 -FontFamily 'Calibri Light' -Supress $True Add-WordPageBreak -WordDocument $reportFile -Supress $true #region TOC ######################################################################################################### Add-WordTOC -WordDocument $reportFile -Title "Table of Content" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Table Of Content" -Color GREEN Add-WordPageBreak -WordDocument $reportFile -Supress $true #endregion TOC ######################################################################################################## #region OU ############################################################################################################ New-InformationLog -LogPath $logFilePath -Message "Started to create Organizational Unit part" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading1 -Text 'Organisational Units List' -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "Organisational Unit" $ous = Get-OUInformation New-InformationLog -LogPath $logFilePath -Message "Information about Organizational Units aquired" -Color GREEN foreach ($ou in $ous) { Add-WordText -WordDocument $reportFile -HeadingType Heading2 -Text $($ou.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($ou.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $ou -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($ou.Name) -Transpose -Supress $True New-InformationLog -LogPath $logFilePath -Message "Created table about $($ou.Name) Organizational Unit" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($ou.Name) Graph" -Supress $true $ouLeaf = $(Get-ADOrganizationalUnit -Filter "*" -SearchBase $($ou.DistinguishedName) -SearchScope OneLevel).Name $ouRoot=$($($ou.DistinguishedName) -split ',*..=')[2] if (($null -eq $ouLeaf) -and ($null -eq $ouRoot)) { Add-WordText -WordDocument $reportFile -Text "$($ou.Name) do not have above and below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($ou.Name) Organizational Unit do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $ouRoot -GraphMiddle $($ou.Name) -GraphLeaf $ouLeaf -BasePathToGraphImage $($reportGraphFolders.OU) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($ou.Name) Organizational Unit have above and below elements" -Color GREEN } #ManagedBy #TEST Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($ou.Name) ManagedBy" -Supress $true $ouTMP = $ou.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $ouTMP) { Add-WordText -WordDocument $reportFile -Text "$($ou.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($ou.Name) Organizational Unit do not have ManagedBy elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $ouTMP -GraphLeaf $($ou.Name) -BasePathToGraphImage $($reportGraphFolders.OU) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($ou.Name) Organizational Unit do have ManagedBy elements" -Color GREEN } #ACL $ouACL = Get-OUAcl -OU $($ou.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($ou.Name) Permissions" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($ouACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "OU Options" -Transpose -Supress $true #MediumShading1Accent5 Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created $($ou.Name) Organizational Unit ACL Table 1" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($ouACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created $($ou.Name) Organizational Unit ACL Table 2" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Organisational Unit Tables" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -Text "Cities and Country Table" -HeadingType Heading3 -Supress $true $ouTable = $($ous | Select-Object Name, StreetAddress, PostalCode, City, State, Country) Add-WordTable -WordDocument $reportFile -DataTable $ouTable -Design ColorfulGridAccent1 -Supress $True #-Verbose New-InformationLog -LogPath $logFilePath -Message "Created Organizational Units Table" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Organisational Unit List" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 changed organisational unit" -Supress $true $list = $($($ous | Select-Object whenChanged, Name | Sort-Object -Descending whenChanged | Select-Object -First 10) | Select-Object @{Name = "OUName"; Expression = { "$($_.Name) - $($_.whenChanged)" } }).OUName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Created Organizational Units List 1" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 created organisational unit" -Supress $true $list = $($($ous | Select-Object whenCreated, Name | Sort-Object -Descending whenCreated | Select-Object -First 10) | Select-Object @{Name = "OUName"; Expression = { "$($_.Name) - $($_.whenCreated)" } }).OUName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Created Organizational Units List 2" -Color GREEN #endregion OU ##################################################################################################### #region GROUPS##################################################################################################### New-InformationLog -LogPath $logFilePath -Message "Started to create Group part" -Color GREEN Add-WordText -WordDocument $reportFile -Text 'Spis Grup' -HeadingType Heading1 -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "Group" $groups = Get-GROUPInformation New-InformationLog -LogPath $logFilePath -Message "Information about groups aquired" -Color GREEN Add-WordText -WordDocument $reportFile -Text "DomainLocal groups" -HeadingType Heading2 -Supress $true $groupObjects=$groups | Where-Object {$_.GroupType -band 1 } New-InformationLog -LogPath $logFilePath -Message "Started to create domain local group part" -Color GREEN foreach ($group in $groupObjects) { Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text $($group.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $group -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($group.Name) -Transpose -Supress $True New-InformationLog -LogPath $logFilePath -Message "Created table about $($group.Name) Group" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Graph" -Supress $true $groupLeafTMP = $group.Members | ForEach-Object { $(($_ -split ',*..=')[1]) } $groupRootTMP = $group.MemberOf | ForEach-Object { $(($_ -split ',*..=')[1]) } if (($null -eq $groupLeafTMP) -and ($null -eq $groupRootTMP)) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above and below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $groupRootTMP -GraphMiddle $($group.Name) -GraphLeaf $groupLeafTMP -pathToImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have Members or is member of other group" -Color GREEN } #ManagedBy Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) ManagedBy" -Supress $true $groupTMP = $group.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $groupTMP) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $groupTMP -GraphLeaf $($group.Name) -BasePathToGraphImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have ManagedBy elements" -Color GREEN } #ACL $groupACL=Get-GROUPAcl -GROUP_ACL $($group.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Permissions" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($groupACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "OU Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Table about $($group.Name) Group" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($groupACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created ACL Table about $($group.Name) Group" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Security Groups" -HeadingType Heading2 -Supress $true $groupObjects=$groups | Where-Object { (-not($_.GroupType -band 1)) -and ($_.GroupCategory -eq "Security") } New-InformationLog -LogPath $logFilePath -Message "Started to create security group part" -Color GREEN foreach ($group in $groupObjects) { Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text $($group.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $group -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($group.Name) -Transpose -Supress $True New-InformationLog -LogPath $logFilePath -Message "Created table about $($group.Name) Group" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Graph" -Supress $true $groupLeafTMP = $group.Members | ForEach-Object { $(($_ -split ',*..=')[1]) } $groupRootTMP = $group.MemberOf | ForEach-Object { $(($_ -split ',*..=')[1]) } if (($null -eq $groupLeafTMP) -and ($null -eq $groupRootTMP)) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above and below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $groupRootTMP -GraphMiddle $($group.Name) -GraphLeaf $groupLeafTMP -pathToImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have members and is MemberOf other group" -Color GREEN } #ManagedBy Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) ManagedBy" -Supress $true $groupTMP = $group.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $groupTMP) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $groupTMP -GraphLeaf $($group.Name) -BasePathToGraphImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have ManagedBy elements" -Color GREEN } #ACL $groupACL=Get-GROUPAcl -GROUP_ACL $($group.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Permissions" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($groupACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "OU Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Table about $($group.Name) Group" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($groupACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created ACL Table about $($group.Name) Group" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Distribution Groups" -HeadingType Heading2 -Supress $true $groupObjects=$groups | Where-Object {$_.GroupCategory -eq "Distribution" } New-InformationLog -LogPath $logFilePath -Message "Started to create distribution group part" -Color GREEN foreach ($group in $groupObjects) { Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text $($group.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $group -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($group.Name) -Transpose -Supress $True New-InformationLog -LogPath $logFilePath -Message "Created table about $($group.Name) Group" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Graph" -Supress $true $groupLeafTMP = $group.Members | ForEach-Object { $(($_ -split ',*..=')[1]) } $groupRootTMP = $group.MemberOf | ForEach-Object { $(($_ -split ',*..=')[1]) } if (($null -eq $groupLeafTMP) -and ($null -eq $groupRootTMP)) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above and below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $groupRootTMP -GraphMiddle $($group.Name) -GraphLeaf $groupLeafTMP -pathToImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have members and is MemberOf other group" -Color GREEN } #ManagedBy Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) ManagedBy" -Supress $true $groupTMP = $group.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $groupTMP) { Add-WordText -WordDocument $reportFile -Text "$($group.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $groupTMP -GraphLeaf $($group.Name) -BasePathToGraphImage $($reportGraphFolders.GROUP) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "$($group.Name) Group have ManagedBy elements" -Color GREEN } #ACL $groupACL=Get-GROUPAcl -GROUP_ACL $($group.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading4 -Text "$($group.Name) Permissions" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($groupACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "OU Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Table about $($group.Name) Group" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($groupACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created ACL Table about $($group.Name) Group" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Group Tables" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -Text "Grup difference" -HeadingType Heading3 -Supress $true $groupTable = $groups | Group-Object GroupScope | ForEach-Object { $categories = $_.Group | Group-Object GroupCategory -AsHashtable -AsString [PSCustomObject]@{ GroupName = $_.Name Security = $categories['Security'].Count Distribution = $categories['Distribution'].Count } } Add-WordTable -WordDocument $reportFile -DataTable $groupTable -Design ColorfulGridAccent1 -Supress $True #-Verbose New-InformationLog -LogPath $logFilePath -Message "Created Group Tables" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Group Lists" -HeadingType Heading2 -Supress $true $list = $($($groups | Select-Object whenChanged, Name | Sort-Object -Descending whenChanged | Select-Object -First 10) | Select-Object @{Name = "GroupName"; Expression = { "$($_.Name) - $($_.whenChanged)" } }).GroupName Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 changed groups" -Supress $true Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose $list = $($($groups | Select-Object whenCreated, Name | Sort-Object -Descending whenCreated | Select-Object -First 10) | Select-Object @{Name = "GroupName"; Expression = { "$($_.Name) - $($_.whenCreated)" } }).GroupName Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 created groups" -Supress $true Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose $list = $($groups | Where-Object { $_.Members.Count -eq 0 }).Name Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Empty Groups" -Supress $true Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Created Group Lists" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Group Charts" -HeadingType Heading2 -Supress $true $chart = $groups | Group-Object GroupCategory | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Barchart" -CData $chart -STitle "Distribution\Security group chart" -CTitle "Ratio between security groups and distribution groups" $chart = $groups | Group-Object GroupScope | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Barchart" -CData $chart -STitle "Local\Global\Universal group chart" -CTitle "Ratio between local groups,global groups and universal groups" New-InformationLog -LogPath $logFilePath -Message "Created Group Graphs" -Color GREEN #endregion GROUPS##################################################################################################### #region USERS##################################################################################################### New-InformationLog -LogPath $logFilePath -Message "Started to create user part" -Color GREEN Add-WordText -WordDocument $reportFile -Text 'Users List' -HeadingType Heading1 -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "User" $users = Get-USERInformation New-InformationLog -LogPath $logFilePath -Message "Information about users aquired" -Color GREEN foreach ($user in $users) { Add-WordText -WordDocument $reportFile -HeadingType Heading2 -Text $($user.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($user.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $user -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($user.Name) -Transpose -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created table about $($user.Name)" -Color GREEN #MemberOf Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($user.Name) MemberOfGroup Graph" -Supress $true if ($null -eq $($user.MemberOf)) { Add-WordText -WordDocument $reportFile -Text "$($user.Name) do not have below elements" -Supress $true $memberOfTMP = $($($($user.PrimaryGroup) -split ',*..=')[1]) $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($user.Name) -GraphLeaf $memberOfTMP -BasePathToGraphImage $($reportGraphFolders.USERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "User $($user.Name) is member of primary group" -Color RED } else { $memberOfTMP = $($($user.MemberOf) + $($user.PrimaryGroup) | ForEach-Object { $(($_ -split ',*..=')[1]) } ) $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($user.Name) -GraphLeaf $memberOfTMP -BasePathToGraphImage $($reportGraphFolders.USERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "User $($user.Name) is member of primary group and other group" -Color RED } #ManagedBy Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($user.Name) ManagedBy" -Supress $true $userTMP = $user.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $userTMP) { Add-WordText -WordDocument $reportFile -Text "$($user.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message " User $($user.Name) do not have above elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $userTMP -GraphLeaf $($user.Name) -BasePathToGraphImage $($reportGraphFolders.USERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "User $($user.Name) have ManagedBy elements" -Color GREEN } #Manager Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($user.Name) DirectManager" -Supress $true $managerTMP = $user.Manager| ForEach-Object { $(($_ -split ',*..=')[1]) } $directReportsTMP = $user.DirectReports | ForEach-Object { $(($_ -split ',*..=')[1]) } if (($null -eq $managerTMP) -and ($null -eq $directReportsTMP)) { Add-WordText -WordDocument $reportFile -Text "$($user.Name) do not have above and below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "User $($user.Name) do not have above and below elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $managerTMP -GraphMiddle $($user.Name) -GraphLeaf $directReportsTMP -BasePathToGraphImage $($reportGraphFolders.USERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "User $($user.Name) have Manager or Direct Employees" -Color GREEN } #TODO:Create graph with full organisation manager and direct report #ACL $userACL = Get-USERAcl -USER_ACL $($user.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($user.Name) Permissions" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($userACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "User Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Table about $($user.Name) User" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($userACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created ACL Table about $($user.Name) User" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Users Table" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -Text "Users Table Location" -HeadingType Heading3 -Supress $true $table = $($users | Select-Object Name, Department, City, Country) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "Security Table" -HeadingType Heading3 -Supress $true $table = $($users | Select-Object Name, CannotChangePassword, PasswordExpired, PasswordNeverExpires, PasswordNotRequired) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created Tables about Users" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Users Lists" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 changed users" -Supress $true $list = $($($users | Select-Object whenChanged, Name | Sort-Object -Descending whenChanged | Select-Object -First 10) | Select-Object @{Name = "UserName"; Expression = { "$($_.Name) - $($_.whenChanged)" } }).UserName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 created users" -Supress $true $list = $($($users | Select-Object whenCreated, Name | Sort-Object -Descending whenCreated | Select-Object -First 10) | Select-Object @{Name = "UserName"; Expression = { "$($_.Name) - $($_.whenCreated)" } }).UserName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Created Lists about Users" -Color GREEN Add-WordText -WordDocument $reportFile -Text "User Charts" -HeadingType Heading2 -Supress $true $chart = $users | Group-Object Enabled | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Barchart" -CData $chart -STitle "Enabled\Disabled accounts chart" -CTitle "The ratio of the number of disabled and enabled accounts" $chart = $users | Group-Object Office | Select-Object Name , @{Name = "Values"; Expression = {[math]::round(((($_.Count) / $users.Count) * 100), 2)} } | Where-Object { $_.Values -ge 1 } | Sort-Object -Descending Values Add-WordChart -CType "Piechart" -CData $chart -STitle "Chart of offices in a cross section of the company" -CTitle "ratio of the number of positions" $chart = $users | Group-Object Title | Select-Object Name, @{Name = "Values"; Expression = { [math]::round(((($_.Count) / $users.Count) * 100), 2)} } | Where-Object { $_.Values -ge 1 } | Sort-Object -Descending Values Add-WordChart -CType "Piechart" -CData $chart -STitle "Chart of positions in the cross-section of the companyy" -CTitle "Chart of positions in the cross-section of the company" $chart = $users | Group-Object Department | Select-Object Name, @{Name = "Values"; Expression = {[math]::round(((($_.Count) / $users.Count) * 100), 2)} } | Where-Object { $_.Values -ge 1 } | Sort-Object -Descending Values Add-WordChart -CType "Piechart" -CData $chart -STitle "Chart of departments in a cross section of the company" -CTitle "Chart of positions in the cross-section of the company" New-InformationLog -LogPath $logFilePath -Message "Created Charts about Users" -Color GREEN #endregion USERS##################################################################################################### #region GPO############################################################################################################ New-InformationLog -LogPath $logFilePath -Message "Started to create GPO part" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading1 -Text 'Group Policy Lists' -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "GPOPolicy" $groupPolicyObjects = Get-GPO -Domain $($Env:USERDNSDOMAIN) -All New-InformationLog -LogPath $logFilePath -Message "Information about GPO aquired" -Color GREEN $groupPolicyObjectsList = foreach ($groupPolicyObject in $groupPolicyObjects) { $gpoObject = Get-GPOPolicy -GroupPolicy $groupPolicyObject Add-WordText -WordDocument $reportFile -HeadingType Heading2 -Text $($gpoObject.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($gpoObject.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $gpoObject -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($gpoObject.Name) -Transpose -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created table about $($gpoObject.Name)" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($gpoObject.Name) Graph" -Supress $true if ($null -eq $($gpoObject.Links)) { Add-WordText -WordDocument $reportFile -Text "$($gpoObject.Name) do not have below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "GPO $($gpoObject.Name) do not have links" -Color RED } else { $linksTMP = $gpoObject.Links.split(";") $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($gpoObject.Name) -GraphLeaf $linksTMP -pathToImage $($reportGraphFolders.GPO) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "GPO $($gpoObject.Name) have links into few AD objects" -Color GREEN } #ACL Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($gpoObject.Name) Permissions Simple" -Supress $true $gpoObjectACL = Get-GPOAclSimple -GroupPolicy $groupPolicyObject $gpoObjectACL.ACL | ForEach-Object { Add-WordTable -WordDocument $reportFile -DataTable $($_) -Design MediumShading1Accent5 -AutoFit Window -Supress $true } New-InformationLog -LogPath $logFilePath -Message "Create ACL tables with GPO $($gpoObject.Name)" -Color GREEN $pathACL = Get-GPOAclExtended -GPO_ACL $($groupPolicyObject.Path) Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($gpoObject.Name) Permissions Extended" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($pathACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "GPO Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Create table with GPO $($gpoObject.Name) information" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($pathACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Create ACL table with GPO $($gpoObject.Name) information" -Color GREEN $gpoObject } Add-WordText -WordDocument $reportFile -Text "GroupPolicy Tables" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -Text "Group Policy table 1" -HeadingType Heading3 -Supress $true $gpoTable = $($groupPolicyObjectsList | Select-Object Name, HasComputerSettings, HasUserSettings, ComputerSettings, UserSettings) Add-WordTable -WordDocument $reportFile -DataTable $gpoTable -Design ColorfulGridAccent1 -Supress $True #-Verbose Add-WordText -WordDocument $reportFile -Text "Group Policy table 2" -HeadingType Heading3 -Supress $true $gpoTable = $($groupPolicyObjectsList | Select-Object Name,UserEnabled, ComputerEnabled) Add-WordTable -WordDocument $reportFile -DataTable $gpoTable -Design ColorfulGridAccent1 -Supress $True #-Verbose New-InformationLog -LogPath $logFilePath -Message "Created tables with information about GPO" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Group Policy Lists" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 modified organisational unit" -Supress $true $list = $($($groupPolicyObjectsList | Select-Object ModificationTime, Name | Sort-Object -Descending ModificationTime | Select-Object -First 10) | Select-Object @{Name = "GPOName"; Expression = { "$($_.Name) - $($_.ModificationTime)" } }).GPOName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 created organisational unit" -Supress $true $list = $($($groupPolicyObjectsList | Select-Object CreationTime, Name | Sort-Object -Descending CreationTime | Select-Object -First 10) | Select-Object @{Name = "GPOName"; Expression = { "$($_.Name) - $($_.CreationTime)" } }).GPOName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Not applied group policies" -Supress $true $list = $($groupPolicyObjectsList | Where-Object { $_.Links.Count -eq 0 }).Name Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Created Lists with information about GPO" -Color GREEN #endregion GPO################################################################################################ #region FGPP################################################################################################## New-InformationLog -LogPath $logFilePath -Message "Started to create FGPP part" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading1 -Text 'Fine Grained Password Policies List' -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "FineGrainedPasswordPolicy" $fgpps = Get-FineGrainedPolicies New-InformationLog -LogPath $logFilePath -Message "Information about GPO aquired" -Color GREEN foreach ($fgpp in $fgpps) { Add-WordText -WordDocument $reportFile -HeadingType Heading2 -Text $($fgpp.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($fgpp.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $fgpp -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($fgpp.Name) -Transpose -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created table about $($fgpp.Name)" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($fgpp.Name) is applied to" -Supress $true if ($null -eq $($fgpp.'Applies To')) { Add-WordText -WordDocument $reportFile -Text "$($fgpp.Name) do not have below elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "FGPP is not applied to objects" -Color RED } else { $fgppAplliedTMP = $($fgpp.'Applies To').split(";") $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($fgpp.Name) -GraphLeaf $fgppAplliedTMP -pathToImage $reportGraphFolders.FGPP Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "FGPP $($fgpp.Name) is applied to few objects" -Color GREEN } } #endregion FGPP############################################################################################### #region COMPUTERS############################################################################################# New-InformationLog -LogPath $logFilePath -Message "Started to create Computer part" -Color GREEN Add-WordText -WordDocument $reportFile -HeadingType Heading1 -Text 'Computers List' -Supress $true Add-Description -DescriptionPath $pathToDescription -DescriptionType "Computer" $computers=Get-ComputerInformation New-InformationLog -LogPath $logFilePath -Message "Information about GPO aquired" -Color GREEN foreach ($computer in $computers) { Add-WordText -WordDocument $reportFile -HeadingType Heading2 -Text $($computer.Name) -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($computer.Name) Information" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $computer -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle $($computer.Name) -Transpose -Supress $true New-InformationLog -LogPath $logFilePath -Message "Created table about $($fgpp.Name)" -Color GREEN #MemberOf Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($computer.Name) MemberOfGroup Graph" -Supress $true if ($null -eq $computerLeafTMP) { Add-WordText -WordDocument $reportFile -Text "$($computer.Name) do not have below elements" -Supress $true $computerLeafTMP = $($($($computer.PrimaryGroup) -split ',*..=')[1]) $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($computer.Name) -GraphLeaf $computerLeafTMP -BasePathToGraphImage $($reportGraphFolders.COMPUTERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "Computer $($computer.Name) is not Member Of groups" -Color RED } else { $computerLeafTMP = $($($computer.PrimaryGroup) + $($computer.MemberOf) | ForEach-Object { $(($_ -split ',*..=')[1]) } ) $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $($computer.Name) -GraphLeaf $computerLeafTMP -BasePathToGraphImage $($reportGraphFolders.COMPUTERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "Computer $($computer.Name) is member of few groups" -Color GREEN } #ManagedBy Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($computer.Name) ManagedBy" -Supress $true $managerTMP = $computer.ManagedBy | ForEach-Object { $(($_ -split ',*..=')[1]) } if ($null -eq $managerTMP) { Add-WordText -WordDocument $reportFile -Text "$($computer.Name) do not have above elements" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Computer $($computer.Name) is not Managed by other elements" -Color RED } else { $imagePath = Get-GraphImage -GraphRoot $null -GraphMiddle $managerTMP -GraphLeaf $($computer.Name) -BasePathToGraphImage $($reportGraphFolders.COMPUTERS) Add-WordPicture -WordDocument $reportFile -ImagePath $imagePath -Alignment center -ImageWidth 600 -Supress $True New-InformationLog -LogPath $logFilePath -Message "Computer $($computer.Name) is Managed by one of elements" -Color GREEN } #ACL $computerACL = Get-GPOAclExtended -GPO_ACL $($computer.DistinguishedName) Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "$($computer.Name) Permissions Extended" -Supress $true Add-WordTable -WordDocument $reportFile -DataTable $($computerACL | Select-Object -Property * -ExcludeProperty ACLs) -Design MediumShading1Accent5 -AutoFit Window -OverwriteTitle "GPO Options" -Transpose -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Create table with Computer $($computer.Name) information" -Color GREEN Add-WordTable -WordDocument $reportFile -DataTable $($computerACL.ACLs) -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "" -Supress $true New-InformationLog -LogPath $logFilePath -Message "Create ACL table with Computer $($computer.Name)" -Color GREEN } Add-WordText -WordDocument $reportFile -Text "Computers Table" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -Text "Address Table" -HeadingType Heading3 -Supress $true $table = $($computers | Select-Object DNSHostName, IP4, IP6,Location) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "Security Table 1" -HeadingType Heading3 -Supress $true $table = $($computers | Select-Object Name,Enabled,LockedOut,PasswordExpired) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "Security Table 2" -HeadingType Heading3 -Supress $true $table = $($computers | Select-Object Name, AllowReversiblePasswordEncryption,CannotChangePassword,PasswordNeverExpires,PasswordNotRequired) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "Security Table 3" -HeadingType Heading3 -Supress $true $table = $($computers | Select-Object Name, AccountNotDelegated,TrustedForDelegation,IsCriticalSystemObject) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true Add-WordText -WordDocument $reportFile -Text "Security Table 4" -HeadingType Heading3 -Supress $true $table = $($computers | Select-Object Name, DoesNotRequirePreAuth,ProtectedFromAccidentalDeletion,USEDESKeyOnly) Add-WordTable -WordDocument $reportFile -DataTable $table -Design MediumShading1Accent5 -AutoFit Window -Supress $true New-InformationLog -LogPath $logFilePath -Message "Create tables with Computers information" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Computer charts" -HeadingType Heading3 -Supress $true $chart = $computers | Group-Object Enabled | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Barchart" -CData $chart -STitle "Computer account enabled\disabled chart" -CTitle "The ratio of the number of computer accounts enabled and disabled" $chart = $computers | Group-Object OperatingSystem | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Piechart" -CData $chart -STitle "Operating systems ratio charts" -CTitle "The ratio of the types of operating systems" $chart = $computers | Group-Object OperatingSystemVersion | Select-Object Name, @{Name="Values";Expression={$_.Count}} Add-WordChart -CType "Piechart" -CData $chart -STitle "Operating system version ratio charts" -CTitle "The ratio of the versions of the operating systems" $chart = $computers | Select-Object Name,@{Name="Values";Expression={$_.LogonCount}} | Sort-Object -Descending Values |Select-Object -First 10 Add-WordChart -CType "Piechart" -CData $chart -STitle "Charts of the most frequently logged in computers" -CTitle "The chart of the most frequently logged on computers" New-InformationLog -LogPath $logFilePath -Message "Create charts with Computers information" -Color GREEN Add-WordText -WordDocument $reportFile -Text "Computers List" -HeadingType Heading2 -Supress $true Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 logging in computers" -Supress $true $list = $($($computers | Select-Object LastLogonDate, Name | Sort-Object -Descending LastLogonDate | Select-Object -First 10) | Select-Object @{Name = "ComputerName"; Expression = { "$($_.Name) - $($_.LastLogonDate)" } }).ComputerName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 computer passwords changed" -Supress $true $list = $($($computers | Select-Object PasswordLastSet, Name | Sort-Object -Descending PasswordLastSet | Select-Object -First 10) | Select-Object @{Name = "ComputerName"; Expression = { "$($_.Name) - $($_.PasswordLastSet)" } }).ComputerName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 changed computers" -Supress $true $list = $($($computers | Select-Object whenChanged, Name | Sort-Object -Descending whenChanged | Select-Object -First 10) | Select-Object @{Name = "ComputerName"; Expression = { "$($_.Name) - $($_.whenChanged)" } }).ComputerName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose Add-WordText -WordDocument $reportFile -HeadingType Heading3 -Text "Last 10 computers created" -Supress $true $list = $($($computers | Select-Object whenCreated, Name | Sort-Object -Descending whenCreated | Select-Object -First 10) | Select-Object @{Name = "ComputerName"; Expression = { "$($_.Name) - $($_.whenCreated)" } }).ComputerName Add-WordList -WordDocument $reportFile -ListType Numbered -ListData $list -Supress $true -Verbose New-InformationLog -LogPath $logFilePath -Message "Create Lists with Computers information" -Color GREEN #endregion COMPUTERS########################################################################################## ############################################################################################################## Save-WordDocument $reportFile -Supress $true -Language "en-US" -Verbose } |