ActiveDirectoryStig.psm1
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 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 |
#Try to import these, but silently continue on error since another module #may use this as a dependency, but doesn't have these installed yet if ((Get-Module -Name ActiveDirectory) -eq $null) { Import-Module -Name ActiveDirectory -ErrorAction SilentlyContinue } Function Set-ActiveDirectoryStigItems { <# .SYNOPSIS Executes all of the Active Directory STIG settings included in the module. .DESCRIPTION The cmdlet runs each audit and configuration setting in the module. It covers items in both the Windows Server Domain Controller STIG and Active Directory STIG. The cmdlet must be run with Enterprise Admin credentials since it sets the configuration for each domain in the entire forest of the current user. .PARAMETER Credential The credentials to run the cmdlet with. .INPUTS System.Management.Automation.PSCredential The input can be piped to Set-ActiveDirectoryStigItems .OUTPUTS None .EXAMPLE Set-ActiveDirectoryStigItems Configures all of the settings in this module. .EXAMPLE Set-ActiveDirectoryStigItems -Credential (Get-Credential) Configures all of the settings in this module using the specified credentials. .NOTES This cmdlet must be run with enterprise admin credentials. AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Warning "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { Set-RIDManagerAuditing -Credential $Credential Set-PolicyContainerAuditing -Credential $Credential Set-MaxConnectionIdleTime -Credential $Credential Set-InfrastructureObjectAuditing -Credential $Credential Set-DsHeuristics -Credential $Credential Set-AdminSDHolderAuditing -Credential $Credential Set-DomainAuditing -Credential $Credential Set-DomainControllersOUAuditing -Credential $Credential Set-NTDSFilePermissions -Credential $Credential } End { } } Function Set-NTDSFilePermissions { <# .SYNOPSIS Active Directory data files must have proper access control permissions. .DESCRIPTION The Set-NTDSFilePermissions cmdlet sets the required security permissions for the database files and log files. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-NTDSFilePermissions Configures the required permissions for the NTDS database and logs .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AD-000001-DC Rule ID SV-51175r2 Vuln ID V-8316 Severity CAT I #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $BuiltinAdministrators = New-Object Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::BuiltinAdministratorsSid, $null) $System = New-Object Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::LocalSystemSid, $null) $CreatorOwner = New-Object Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::CreatorOwnerSid, $null) $LocalService = New-Object Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::LocalServiceSid, $null) $AdministratorAce = New-Object System.Security.AccessControl.FileSystemAccessRule($BuiltinAdministrators, [System.Security.AccessControl.FileSystemRights]::FullControl, @([System.Security.AccessControl.InheritanceFlags]::ObjectInherit, [System.Security.AccessControl.InheritanceFlags]::ContainerInherit), [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow ) $SystemAce = New-Object System.Security.AccessControl.FileSystemAccessRule($System, [System.Security.AccessControl.FileSystemRights]::FullControl, @([System.Security.AccessControl.InheritanceFlags]::ObjectInherit, [System.Security.AccessControl.InheritanceFlags]::ContainerInherit), [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow ) $CreatorOwnerAce = New-Object System.Security.AccessControl.FileSystemAccessRule($CreatorOwner, [System.Security.AccessControl.FileSystemRights]::FullControl, @([System.Security.AccessControl.InheritanceFlags]::ObjectInherit, [System.Security.AccessControl.InheritanceFlags]::ContainerInherit), [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow ) $LocalServiceAce = New-Object System.Security.AccessControl.FileSystemAccessRule($LocalService, @([System.Security.AccessControl.FileSystemRights]::AppendData, [System.Security.AccessControl.FileSystemRights]::CreateDirectories), [System.Security.AccessControl.InheritanceFlags]::ContainerInherit, [System.Security.AccessControl.PropagationFlags]::None, [System.Security.AccessControl.AccessControlType]::Allow ) ([System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Domains | ForEach-Object { $_.DomainControllers | Select-Object -ExpandProperty Name | ForEach-Object { Write-Host ("Reviewing Domain Contoller " + $_) $NTDS = Invoke-Command -ScriptBlock { Get-ItemProperty -Path "HKLM:\\System\\CurrentControlSet\\Services\\NTDS\\Parameters" } -ComputerName $_ $DSA = $NTDS.'DSA Database File' $Logs = $NTDS.'Database log files path' $DSA = "\\$_\\" + $DSA.Replace(":\","$\").Replace("\", "\\") $Logs = "\\$_\\" + $Logs.Replace(":\","$\").Replace("\", "\\") $DSA = $DSA.Substring(0, $DSA.LastIndexOf("\\")) $ACL1 = Get-Acl -Path $DSA foreach ($Rule in $ACL1.Access) { $ACL1.RemoveAccessRule($Rule) | Out-Null } $ACL1.AddAccessRule($AdministratorAce) $ACL1.AddAccessRule($SystemAce) Write-Host "Setting $DSA ACL" Set-Acl -Path $DSA -AclObject $ACL1 Get-ChildItem -Path $DSA | ForEach-Object { $Acl = Get-Acl -Path $_.FullName foreach ($Rule in $Acl.Access) { if (-not $Rule.IsInherited) { $Acl.RemoveAccessRule($Rule) | Out-Null } } Set-Acl -Path $_.FullName -AclObject $Acl } $ACL2 = Get-Acl -Path $Logs foreach ($Rule in $ACL2.Access) { $ACL2.RemoveAccessRule($Rule) | Out-Null } $ACL2.AddAccessRule($AdministratorAce) $ACL2.AddAccessRule($SystemAce) $ACL2.AddAccessRule($LocalServiceAce) $ACL2.AddAccessRule($CreatorOwnerAce) Write-Host "Setting $Logs ACL" Set-Acl -Path $Logs -AclObject $ACL2 Get-ChildItem -Path $Logs | ForEach-Object { $Acl = Get-Acl -Path $_.FullName foreach ($Rule in $Acl.Access) { if (-not $Rule.IsInherited) { $Acl.RemoveAccessRule($Rule) | Out-Null } } Set-Acl -Path $_.FullName -AclObject $Acl } } } } End { } } Function Set-RIDManagerAuditing { <# .SYNOPSIS The Active Directory RID Manager$ object must be configured with proper audit settings. .DESCRIPTION The Set-RIDManagerAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-RIDManagerAuditing Configures the required auditing for the RID Manager object. .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000212-DC Rule ID SV-51174r2 Vuln ID V-39330 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-RIDManagerAuditRuleSet Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "CN=RID Manager$,CN=System" } } End { } } Function Set-PolicyContainerAuditing { <# .SYNOPSIS Active Directory Group Policy objects must be configured with proper audit settings. .DESCRIPTION The Set-PolicyContainerAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-PolicyContainerAuditing Configures the required auditing for the Group Policy container. .INPUTS None .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000207-DC Rule ID SV-51169r4 Vuln ID V-39325 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-PolicyContainerAuditRuleSet Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "CN=Policies,CN=System" } } End { } } Function Set-MaxConnectionIdleTime { <# .SYNOPSIS The directory service must be configured to terminate LDAP-based network connections to the directory server after five (5) minutes of inactivity. .DESCRIPTION The Set-MaxConnectionIdleTime cmdlet sets the timeout for inactive connections. The command must be run with Enterprise Admin credentials. .PARAMETER MaxConnIdleTime The timeout for inactive network connections. Defaults to 5 minutes. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-MaxConnectionIdleTime Sets the connection idle time setting to 5 minutes (default). .EXAMPLE Set-MaxConnectionIdleTime -MaxConnIdleTime 180 Sets the connection idle time setting to 3 minutes .INPUTS System.Int32 .OUTPUTS System.String .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AD-000014-DC Rule ID SV-51188r2 Vuln ID V-14831 Severity CAT III #> [CmdletBinding()] Param ( [Parameter(Position=0, ValueFromPipeline=$true)] [ValidateScript({ $_ -gt 0 })] [System.Int32]$MaxConnIdleTime = 300, [Parameter(Position=1)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Warning "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { [string]$DomainDN = [System.String]::Empty if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) { $Role = Get-WmiObject -Class Win32_OperatingSystem -Property ProductType | Select-Object -ExpandProperty ProductType if ($Role -eq 2) { $DomainDN = Get-ADDomain -Identity (Get-ADForest -Current LoggedOnUser -Server $env:COMPUTERNAME).RootDomain -Server $env:COMPUTERNAME | Select-Object -ExpandProperty DistinguishedName } } if ([System.String]::IsNullOrEmpty($DomainDN)) { $DomainDN = Get-ADDomain -Identity (Get-ADForest -Current LoggedOnUser).RootDomain | Select-Object -ExpandProperty DistinguishedName } [string]$SearchBase = "CN=Query-Policies,CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration," + $DomainDN [Microsoft.ActiveDirectory.Management.ADEntity]$Policies = get-adobject -SearchBase $SearchBase -Filter 'ObjectClass -eq "queryPolicy" -and Name -eq "Default Query Policy"' -Properties * $AdminLimits = [Microsoft.ActiveDirectory.Management.ADPropertyValueCollection]$Policies.lDAPAdminLimits for ($i = 0; $i -lt $AdminLimits.Count; $i++) { if ($AdminLimits[$i] -match "MaxConnIdleTime=*") { break } } if ($i -lt $AdminLimits.Count) { $AdminLimits[$i] = "MaxConnIdleTime=$MaxConnIdleTime" } else { $AdminLimits.Add("MaxConnIdleTime=$MaxConnIdleTime") } if ($Credential -ne [System.Management.Automation.PSCredential]::Empty -and $Credential -ne $null) { Set-ADObject -Identity $Policies -Clear lDAPAdminLimits -Credential $Credential foreach ($Limit in $AdminLimits) { Set-ADObject -Identity $Policies -Add @{lDAPAdminLimits=$Limit} -Credential $Credential } } else { Set-ADObject -Identity $Policies -Clear lDAPAdminLimits foreach ($Limit in $AdminLimits) { Set-ADObject -Identity $Policies -Add @{lDAPAdminLimits=$Limit} } } Write-Output -InputObject (Get-ADObject -Identity $Policies -Properties * | Select-Object -ExpandProperty lDAPAdminLimits | Where-Object {$_ -match "MaxConnIdleTime=*"}) } End { } } Function Set-InfrastructureObjectAuditing { <# .SYNOPSIS The Active Directory Infrastructure object must be configured with proper audit settings. .DESCRIPTION The Set-InfrastructureObjectAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-InfrastructureObjectAudting Configures the required auditing for the infrastructure object. .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 12/5/2015 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000209-DC Rule ID SV-51171r2 Vuln ID V-39327 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-InfrastructureObjectAuditRuleSet Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "CN=Infrastructure" } } End { } } Function Set-DsHeuristics { <# .SYNOPSIS The dsHeuristics option can be configured to override the default restriction on anonymous access to AD data above the rootDSE level. Directory data (outside the root DSE) of a non-public directory must be configured to prevent anonymous access. .DESCRIPTION The Set-DsHeuristics cmdlet configures anonymous access to AD data. The command must be run with Enterprise Admin credentials. .PARAMETER AddAnonymousAccess Adds anonymous read access to the AD Forest .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-DsHeuristic Removes anonymous access from the AD Forest .EXAMPLE Set-DsHeuristic -AddAnonymousRead Adds anonymous read access to the AD Forest .INPUTS System.Management.Automation.SwitchParameter, System.Management.Automation.PSCredential .OUTPUTS System.String .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Active Directory Forest V2R5 1/23/2015 Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID AD.0230 WN12-AD-000013-DC Rule ID SV-9052r2 SV-52838r1 Vuln ID V-8555 V-1070 Severity CAT II #> [CmdletBinding()] Param ( [Parameter()] [switch]$AddAnonymousRead, [Parameter()] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $DN = ("CN=Directory Service,CN=Windows NT,CN=Services,CN=Configuration," + (Get-ADDomain -Identity (Get-ADForest -Current LocalComputer).RootDomain).DistinguishedName) $DirectoryService = Get-ADObject -Identity $DN -Properties dsHeuristics [string]$Heuristic = $DirectoryService.dsHeuristics [array]$Array = @() if ($AddAnonymousRead) { if($Heuristic -ne $null -and $Heuristic -ne [System.String]::Empty) { $Array = $Heuristic.ToCharArray() if ($Array.Length -lt 7) { for ($i = $Array.Length; $i -lt 6; $i++) { $Array += "0" } $Array += "2" } else { $Array[6] = "2" } } else { $Array = "0000002" } } else { if (($Heuristic -ne $null) -and ($Heuristic -ne [System.String]::Empty) -and ($Heuristic.Length -ge 7)) { $Array = $Heuristic.ToCharArray() $Array[6] = "0"; } else { $Array = "0000000" } } [string]$Heuristic = "$Array".Replace(" ", [System.String]::Empty) if ($Heuristic -ne $null -and $Heuristic -ne [System.String]::Empty) { if ($Credential -ne [System.Management.Automation.PSCredential]::Empty -and $Credential -ne $null) { Set-ADObject -Identity $DirectoryService -Replace @{dsHeuristics = $Heuristic} -Credential $Credential } else { Set-ADObject -Identity $DirectoryService -Replace @{dsHeuristics = $Heuristic} } } $Result = Get-ADObject -Identity $DirectoryService -Properties dsHeuristics | Select-Object -ExpandProperty dsHeuristics if ($Result -ne $null) { Write-Output ("dsHeuristics: " + $Result) } else { Write-Warning "dsHeuristics is not set" Exit 1 } } End { } } Function Set-DomainControllersOUAuditing { <# .SYNPOSIS The Active Directory Domain Controllers Organizational Unit (OU) object must be configured with proper audit settings. .DESCRIPTION The Set-DomainControllersOUAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-DomainControllersOUAuditing Configures the required auditing for the domain controller OU. .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000210-DC Rule ID SV-51172r2 Vuln ID V-39328 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-DomainControllersAuditRuleSet Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "OU=Domain Controllers" } } End { } } Function Set-DomainAuditing { <# .SYNOPSIS The Active Directory Domain object must be configured with proper audit settings. .DESCRIPTION The Set-DomainAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-DomainAudting Configures the required auditing for the domain .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000208-DC Rule ID SV-51170r2 Vuln ID V-39326 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-DomainAuditRuleSet -DomainSID (Get-ADDomain -Identity $Domain | Select-Object -ExpandProperty DomainSID) Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "" } } End {} } Function Set-AdminSDHolderAuditing { <# .SYNOPSIS The Active Directory AdminSDHolder object must be configured with proper audit settings. .DESCRIPTION The Set-AdminSDHolderAuditing cmdlet sets the required auditing. The command must be run with Enterprise Admin credentials. .PARAMETER Credential The credentials to use to make the change. The command must be run with Enterprise Admin credentials. .EXAMPLE Set-AdminSDHolderAuditing Configures the required auditing for the AdminSDHolder object. .INPUTS System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 .FUNCTIONALITY STIG Windows Server 2012 / 2012 R2 Domain Controller V2R3 STIG ID WN12-AU-000211-DC Rule ID SV-51173r2 Vuln ID V-39329 Severity CAT II #> [CmdletBinding()] Param( [Parameter(Position=0,ValueFromPipeline=$true)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { if (!(Test-IsEnterpriseAdmin -Credential $Credential)) { Write-Error "The cmdlet must be run with Enterprise Admin credentials." Exit 1 } } Process { $Domains = Get-ForestDomains foreach ($Domain in $Domains) { [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = New-EveryoneAuditRuleSet Set-Auditing -Domain $Domain -Rules $Rules -ObjectCN "CN=AdminSDHolder,CN=System" } } End { } } Function Set-Auditing { <# .SYNOPSIS Sets auditing on an Active Directory object. .DESCRIPTION The Set-Auditing cmdlet applies an audit rule set to an AD object. .PARAMETER Domain The domain to set the auditing in. .PARAMETER ObjectCN The CN of the object to set auditing on up to the domain part of the DN. This can be an emptry string to set auditing on the domain. .PARAMETER Rules The array of ActiveDirectoryAuditRule. .EXAMPLE Set-Auditing -Domain contoso.com -ObjectCN "CN=Policies,CN=System" -Rules $Rules Implements the audit rules. .INPUTS System.String, System.String, System.DirectoryServices.ActiveDirectoryAuditRule[], System.Management.Automation.PSCredential .OUTPUTS None .NOTES AUTHOR: Michael Haken LASTEDIT: 2/27/2016 #> [CmdletBinding()] Param ( [Parameter(Position=0,Mandatory=$true)] [string]$Domain, [Parameter(Position=1,Mandatory=$true)] [AllowEmptyString()] [String]$ObjectCN, [Parameter(Position=2,Mandatory=$true)] [System.DirectoryServices.ActiveDirectoryAuditRule[]]$Rules, [Parameter(Position=3)] [ValidateNotNull()] [System.Management.Automation.PSCredential] [System.Management.Automation.Credential()] $Credential = [System.Management.Automation.PSCredential]::Empty ) Begin { } Process { $DN = (Get-ADDomain -Identity $Domain).DistinguishedName [String[]]$Drives = Get-PSDrive | Select-Object -ExpandProperty Name if ($DC -ne $null) { if (Test-Connection -ComputerName $DC) { $TempDrive = "tempdrive" if ($Drives.Contains($TempDrive)) { Write-Host "An existing PSDrive exists with name $TempDrive, temporarily removing" -ForegroundColor Yellow $OldDrive = Get-PSDrive -Name $TempDrive Remove-PSDrive -Name $TempDrive } $Drive = New-PSDrive -Name $TempDrive -Root "" -PSProvider ActiveDirectory -Server $Domain Push-Location -Path "$Drive`:\" if ($ObjectCN -eq "") { $ObjectDN = $DN } else { $ObjectDN = $ObjectCN + "," + $DN } $ObjectToChange = Get-ADObject -Identity $ObjectDN -Server $Domain $Path = $ObjectToChange.DistinguishedName try { $Acl = Get-Acl -Path $Path -Audit if ($Acl -ne $null) { foreach ($Rule in $Rules) { $Acl.AddAuditRule($Rule) } Set-Acl -Path $Path -AclObject $Acl Write-Results -Path $Path -Domain $Domain } else { Write-Warning "Could not retrieve the ACL for $Path" } } catch [System.Exception] { Write-Warning $_.ToString() } Pop-Location Remove-PSDrive $Drive if ($OldDrive -ne $null) { Write-Host "Recreating original PSDrive" -ForegroundColor Yellow New-PSDrive -Name $OldDrive.Name -PSProvider $OldDrive.Provider -Root $OldDrive.Root | Out-Null $OldDrive = $null } } else { Write-Host "Could not contact domain controller $DC" -ForegroundColor Red } } } End { } } Function New-InfrastructureObjectAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for auditing the Infrastructure object. .DESCRIPTION The New-InfrastructureObjectAuditRuleSet cmdlet creates the required audit rule set for auditing the Infrastructure object. .EXAMPLE New-InfrastructureObjectAuditRuleSet Creates the audit rules. .INPUTS None .OUTPUTS [System.DirectoryServices.ActiveDirectoryAuditRule[]] .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 #> [CmdletBinding()] Param() Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) #$objectguid = "cc17b1fb-33d9-11d2-97d4-00c04fd8d5cd" #Guid for change infrastructure master extended right if it was needed $EveryoneSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, @([System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight), [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $EveryoneSuccess) Write-Output -InputObject $Rules } End { } } Function New-DomainControllersAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for auditing the domain controller's OU. .DESCRIPTION The New-DomainControllerAuditRuleSet cmdlet creates the required audit rule set for auditing the Domain Controller's OU. .EXAMPLE New-DomainControllersAuditRuleSet Creates the audit rules. .INPUTS None .OUTPUTS System.DirectoryServices.ActiveDirectoryAuditRule[] .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 #> [CmdletBinding()] Param() Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $EveryoneWriteDaclSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl, [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $EveryoneWritePropertySuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::All) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $EveryoneWriteDaclSuccess, $EveryoneWritePropertySuccess) Write-Output -InputObject $Rules } End { } } Function New-EveryoneAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for Everyone success and failures. .DESCRIPTION The New-EveryoneAuditRuleSet cmdlet creates the an audit rule set for success and failure on Everyone. .EXAMPLE New-EveryoneAuditRuleSet Creates the audit rules. .INPUTS None .OUTPUTS System.DirectoryServices.ActiveDirectoryAuditRule[] .NOTES AUTHOR: Michael Haken LASTEDIT: 2/27/2016 #> [CmdletBinding()] Param() Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $EveryoneSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, @([System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl, [System.DirectoryServices.ActiveDirectoryRights]::WriteOwner), [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $EveryoneSuccess) Write-Output -InputObject $Rules } End { } } Function New-DomainAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for domain object auditing. .DESCRIPTION The New-DomainAuditRuleSet cmdlet creates the audit rule set for the domain object. .PARAMETER DomainSID The domain SID object for the domain to associate teh rule set with. .EXAMPLE New-DomainAuditRuleSet Creates the audit rules. .INPUTS System.Security.Principal.SecurityIdentifier .OUTPUTS System.DirectoryServices.ActiveDirectoryAuditRule[] .NOTES AUTHOR: Michael Haken LASTEDIT: 2/27/2016 #> [CmdletBinding()] Param ( [Parameter(Position=0,ValueFromPipeline=$true,Mandatory=$true)] [System.Security.Principal.SecurityIdentifier]$DomainSID ) Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $DomainUsers = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::AccountDomainUsersSid, $DomainSID) $Administrators = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::BuiltinAdministratorsSid, $DomainSID) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $DomainUsersSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($DomainUsers, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight, [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $AdministratorsSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Administrators, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight, [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $EveryoneSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, @([System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl, [System.DirectoryServices.ActiveDirectoryRights]::WriteOwner), [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $DomainUsersSuccess, $AdministratorsSuccess, $EveryoneSuccess) Write-Output -InputObject $Rules } End { } } Function New-PolicyContainerAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for the Group Policy container. .DESCRIPTION The New-PolicyContainerAuditRuleSet cmdlet creates the required auditing rule set for group policy objects. .EXAMPLE New-PolicyContainerAuditRuleSet Creates the audit rules. .INPUTS None .OUTPUTS System.DirectoryServices.ActiveDirectoryAuditRule[] .NOTES AUTHOR: Michael Haken LAST UPDATED: 2/27/2016 #> [CmdletBinding()] Param() Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::All) $EveryoneSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, @([System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.DirectoryServices.ActiveDirectoryRights]::WriteDacl), [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::Descendents) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $EveryoneSuccess) Write-Output -InputObject $Rules } End { } } Function New-RIDManagerAuditRuleSet { <# .SYNOPSIS Creates the audit rule set for the RID Manager object. .DESCRIPTION The New-RIDManagerAuditRuleSet cmdlet sets the required auditing for the RID Manager object. .EXAMPLE New-RIDManagerAuditRuleSet Creates the audit rules. .INPUTS None .OUTPUTS System.DirectoryServices.ActiveDirectoryAuditRule[] .NOTES AUTHOR: Michael Haken LAST UPDATED: 2/27/2016 #> [CmdletBinding()] Param() Begin { } Process { $Everyone = New-Object System.Security.Principal.SecurityIdentifier([System.Security.Principal.WellKnownSidType]::WorldSid, $null) $EveryoneFail = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, [System.DirectoryServices.ActiveDirectoryRights]::GenericAll, [System.Security.AccessControl.AuditFlags]::Failure, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) $EveryoneSuccess = New-Object System.DirectoryServices.ActiveDirectoryAuditRule($Everyone, @([System.DirectoryServices.ActiveDirectoryRights]::WriteProperty, [System.DirectoryServices.ActiveDirectoryRights]::ExtendedRight), [System.Security.AccessControl.AuditFlags]::Success, [System.DirectoryServices.ActiveDirectorySecurityInheritance]::None) [System.DirectoryServices.ActiveDirectoryAuditRule[]] $Rules = @($EveryoneFail, $EveryoneSuccess) Write-Output -InputObject $Rules } End{ } } Function Get-ForestDomains { <# .SYNOPSIS Gets all of the domains in the current Active Directory Forest. .DESCRIPTION The Get-ForestDomains cmdlet gets all of the domains in the current Active Directory Forest. .EXAMPLE Get-ForestDomains Gets all of the domains in the Forest of the logged on user. .INPUTS None .OUTPUTS System.String[] .NOTES AUTHOR: Michael Haken LAST UPDATED: 2/27/2016 #> [CmdletBinding()] Param () Begin { } Process { try { $Forest = Get-ADForest -Current LocalComputer $ForestDN = (Get-ADDomain -Identity ($Forest.RootDomain)).DistinguishedName Write-Output -InputObject $Forest.Domains } catch [System.Exception] { Write-Warning $_.Exception.Message Exit 1 } } End { } } Function Write-Results { <# .SYNOPSIS Writes the ACL configuration output results. .DESCRIPTION The Write-Results cmdlet outputs the modified ACL. .PARAMETER Path The path of the Active Directory object to get the ACL of. .PARAMETER Domain The domain the object belongs to. .EXAMPLE Write-Results -Path "dc=contso,sc=com" -Domain "contoso.com" Writes the current ACL of the domain object. .INPUTS None .OUTPUTS System.Security.AccessControl.AuthorizationRuleCollection .NOTES AUTHOR: Michael Haken LAST UPDATE: 2/27/2016 #> [CmdletBinding()] Param ( [Parameter(Position=0,Mandatory=$true)] [string]$Path, [Parameter(Position=1,Mandatory=$true)] [string]$Domain ) Begin { } Process { $Acl = Get-Acl -Path $Path Write-Host $Domain -ForegroundColor DarkRed -BackgroundColor White Write-Host ($Path.Substring($Path.IndexOf(":") + 1)) -ForegroundColor DarkRed -BackgroundColor White Write-Output -InputObject $Acl.Access } End { } } |