PowerShell Check Everyone on Drive Root

<#
      Purpose of script was to check all systems; 
      Check to see if the Everyone group in the 
      root NTFS permissions for seconary hard drives.
      --
      Requires Admin Rights on Remote Machines
      Requires Active Directory Module 
   #>

  
  #====================================================================
  # Command to Check for Everyone Group on Any Other Drives than C:\
  #====================================================================

  $MyCommand={
      #Decalre Array
      $MyArray=@()
     
#Get List of Drives
      $MyDrives=Get-WmiObject Win32_LogicalDisk | Where{($_.Size -ne $Null) -and ($_.DeviceID -ne "C:")} | Select -ExpandProperty DeviceID
     
#If Drives Exists
      If($MyDrives -ne $Null){
          #Loop Through Drive 
          Foreach($Drive in $MyDrives){
             
#Decalre Array
              $MyData=@()
             
#Gets ACL on Drive
              $MyData=get-acl $Drive
                 
#Loop Through Users / Groups Searching for Match of Everyone
                  Foreach($Item in $MyData.Access.IdentityReference){
                       
  #If Finds Add to Array or Else
                          If($Item -like "*Everyone*"){
                              $MyArray+="$Env:Computername - $Drive - $Item - Failed Check"
                          }Else{
                              $MyArray+="$Env:Computername - $Drive - $Item - Passed Check"
                          }
                  }
          }
         
#Returns Date
          Return $MyArray
      }Else{
         
#If No Spare Drives Found 
          Return "$Env:Computername - No Spare Drives"
      }
  }
  

  #==========================================================
  # Command to Query Active Directory for Active Systems 
  #==========================================================

  $Computers=Get-ADComputer -properties * -Filter * | Where{($_.Operatingsystem -like "Windows*") -and ($_.Enabled -eq $True)} | Select -ExpandProperty Name 
  #Makes all Systems Upper CASE (I Like it Like that)
  $MyCAPComputers=$Computers.ToUpper()

  
  #====================================================================
  # Command to Check for Systems online that respond to WinRM
  #====================================================================

  #Declare Array For Passing Systems 
  $MyComputersPassWinRM=@()  
  Foreach ($Comp in $MyCAPComputers){
      if ((Test-Connection -ErrorAction SilentlyContinue –ComputerName $Comp –Quiet –Count 1) –and ((Invoke-Command -ErrorAction SilentlyContinue –ComputerName $comp –ScriptBlock { 1 }) –eq 1)){
          $MyComputersPassWinRM+=$Comp
      }
  }
  

  #====================================================================
  # Command to run against all systems that passed WinRM test :)
  #====================================================================

  Invoke-Command $MyComputersPassWinRM -ScriptBlock $MyCommand | Tee-Object C:\temp\Secondary-Hard-Drives-PCN.txt

2020 | Scott W. Head  |  Sr. Systems Admin | Certified Microsoft Windows Server Administrator