Tuesday, April 7, 2020

O365 OneDrive Migration Collecting Users Network Data

Below PowerShell script will assist with gathering AD user’s information. Such information can be used for OneDrive migrations for O365 work. Script is pretty easy to use , and Function can be utilized in different ways.



<#    

.NOTES
#=============================================
# Script      : Function-Home-Directory-Size.ps1
# Created     : ISE 3.0 
# Author(s)   : Casey.Dedeal 
# Date        : 04/07/2020 09:24:18 
# Org         : ETC Solutions
# File Name   : Function-Home-Directory-Size.ps1
# Comments    : AD reports Users Home Drive information
# Assumptions : Running against ADDS directory
#==============================================

SYNOPSIS           : Function-Home-Directory-Size.ps1
DESCRIPTION        : Gathering AD users home drive sizes
Acknowledgements   : Open license
Limitations        : None
Known issues       : None
Credits            : None

.EXAMPLE
  .\Function-Home-Directory-Size.ps1  -UserName <UserName>

 
  # Single User Report
 
  $userName = 'Casey.DeDeal'
  $userInfo = Function-Home-Directory-Size.ps1 -User $userName
  $userInfo
  $userInfo | export-CSV -Path $CSVfile -NoTypeInformation

  #Multiple User Report

  (a)_.Run the Function agains multiple user within the array
  (b)_.Array can be constructed in multiple ways
  (c)_.Read-CSV
  (d)_.$list = Load users into variable


  # Adjust properties of get ADuser
   Get-ADUser $userAccount -properties * | select any available attribute

  MAP:
  -----------
  #(1)_.Create Log folder
  #(2)_.Check Folder
  #(3)_.Function AD user Home drive Information
  #(4)_.Enter the Array
  #(5)_.Enter Loop
  #(6)_.Export results
  #(7)_.Open report folder

#>


#(1)_.Create Log folder
$name     = 'AD-UsersReport'
$now      = Get-Date -format "dd-MMM-yyyy-HH-mm"
$user     = $env:USERNAME
$desFol   = "C:\Users\$user\Desktop\Reports_\Report\$name\"
$fname    = "$name-$now.CSV"
$CSVfile  = $desFol+$fname

#(2)_.Check Folder
If (!(Test-Path $desFol)) {
New-Item -ItemType Directory -Force $desFol | Out-Null
}

#(3)_.Function AD user Home drive Information
Function Function-Get-AD-Users-H-Drive-Size
{
       Param
       (
              [Parameter(ValueFromPipeline=$true,Mandatory=$true)]
             [Microsoft.ActiveDirectory.Management.ADUser]$User
       )
       Begin
       {
             $array = @()
             $size = $null
       }
       Process
       {
             ForEach($userAccount in $User)
             {
                    Write-Progress "Scanning: ($UserAccount)"
            $userAccount = Get-ADUser $userAccount -properties * | `
                           Select name,homeDirectory,mail
                    $HomeDirsize = Get-ChildItem $userAccount.homeDirectory -recurse | Measure-Object -property length -sum
                   
           If($userAccount.homeDirectory -eq $null)
                    {
                          Write-Host "`nERROR OCCOURED -- User: $userAccount has no Home Directory`n" -foregroundcolor DarkRed -BackgroundColor White
                          Return
                    }

              $objectProperty = [ordered]@{
                UserName          = $userAccount.name
                homeDirectory     = $userAccount.homeDirectory
                HomeDirectorySize = $HomeDirsize.sum
                MailAddress       = $userAccount.mail
            }

            $PSobj = New-Object -TypeName psobject -Property $objectProperty
            $array += $PSobj
                   
              }
       }
       End
       {
             $array
       }
}



#(4)_.Enter the Array

$Array = @(

'User1'
'User2'
'User3'
'User4'
'User5'

)

write-host $null
$result=@()
$i = 1

#(5)_.Enter Loop
$Loop = foreach ($user in $array)
{
   
Write-Host "($i)processing" $user -ForegroundColor DarkYellow
Function-Get-AD-Users-H-Drive-Size -User $user
$i++
}

#(6)_.Export results
$Loop | export-CSV -Path $CSVfile -NoTypeInformation

#(7)_.Open report folder
read-host 'Press <ENTER> to open report folder'
start $desFol




Casey, Dedeal

Azure Solutions Architect
AWS Certified Cloud Practitioner



No comments:

Post a Comment

Microsoft M365 F3 licensing Limitations and Confusion

If you are working in regulated environment you could be dealing with F3 license for some of your users and I am sure you have read MS licen...