Can I speed this up?


hello,

i'm quite new powershell , way can pass on variables , object , such.
currently i'm working on script lists home-directories in specified share , puts in variable. variable filled (all)ad-useraccounts with some properties such homedirectory, profiledirectory etc..

i want know folder i'm looking @ "attached" user (the homedirectory property). need because in old days removal of old data not realy done properly. i'm looping through homedirectory variable within loop, loop throught activedirectory variable find match. way of looping works results want. takes very long loop through variables (it costs around 13 minutes for 150 homedirectories and 5228 ad accounts, , reduced set of homefolders, real scan bigger). there way speed process up?

this loop use (i stripped bit make more readable)

:folderloop foreach ( $folder in $current_folders ) {
    #here i'm setting variables
    :userresultloop foreach ($objresult in $colresults) {
           $objsearched = $objresult.properties
           #here i'm setting variables
           if ([string]$objsearched.homedirectory -eq $folder.fullname){
                  # here i'm writing info excell object
                  $found = $true
                  break :userresultloop
          }
   }
    
   if ($found -ne $true ){
       # here i'm writing info excell object
   }
}

thanks in advance,

raymond

something else might speed this:

$folderlist = $current_folders  | sort lastwritetime -desc | foreach-object {$_.fullname} 

assuming -contains going check through $folderlist in order, gets hit, it's going return $true, , quit.  if sort folders lastwritetime first, active folders should @ top of list, , old, forgotten ones @ bottom.



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

WIMMount (HSM) causing cluster storage to go redirected (2012r2 DC)

Failed to delete the test record dcdiag-test-record in zone test.com

Azure MFA with Azure AD and RDS