Compare hostnames and leases between CSV and DHCP info
Piping the DHCP calls through foreach-object instead and then comparing at the end, cut the time down from 3min to 1min. Everything I have read made it seem like foreach was faster. Having DHCP being processed down the pipe with foreach-object instead of several iterations with foreach makes foreach-objects more efficient.
$servers = Get-DHCPServerInDC
$hashtable = @{}

# scopes into the leases to go into the PsCustomObject to be matched later
$leases = $servers | ForEach-Object {
    $server = $_.dnsname
    Get-DHCPServerv4Scope -computerName $server  #get scopes on DHCP serves
    
    } | ForEach-Object {
    $scope = $_
    $_ | Get-DHCPServerV4Lease -ComputerName $server | #get leases in all the scopes
    
     ForEach-Object {
        [pscustomobject]@{ # Make object to match later
        ScopeName = $scope.name #want name of scope only
        HostName  = $_.hostname #want hostname of leases
        }
    }
}



$assets = (Import-CSV c:\script\Asset_List.csv).asset #pull asset list
 
$assets | ForEach-Object { $asset = $_ #Go through hostnames finding matching lease

    $leases | Where-Object { #check leases
        $_.HostName -like &quot;${asset}*&quot; #find hostname 
    } | ForEach-Object {
        $hashtable[$asset] = $_.ScopeName #store matches
    }
}
```