Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ADUsers = Get-ADUser -Filter *
- $ADUsersHT = @{}
- [collections.arraylist]$ADUsersArray = @()
- foreach ($aduser in $ADUsers){
- $ADUsersHT.Add($aduser.Samaccountname,$aduser)
- $null = $ADUsersArray.Add($aduser)
- }
- $ADusersCSV = $ADUsers | ConvertTo-CSV | ConvertFrom-Csv
- $ADUsersJSON = $AdusersCSv | ConvertTo-Json | ConvertFrom-Json
- $users = @()
- for ($i=0;$i -lt 100;$i++){
- $users += $adusers[$(Get-Random -Minimum 0 -Maximum ($ADUsers.Count - 1))].Samaccountname
- }
- $ADCounter = 0
- $ADObjectsCounter = 0
- $ADObjectsForeachbreakCounter = 0
- $ADObjectsForeachCounter = 0
- $ADObjectsWhereCounter = 0
- $ADObjectsWhereFirstCounter = 0
- $CSVCounter = 0
- $CSVWhereCounter = 0
- $CSVWhereFirstCounter = 0
- $JSONCounter = 0
- $JSONForeachbreakCounter = 0
- $JSONForeachCounter = 0
- $ArrayCounter = 0
- $HTCounter = 0
- $Counter1
- $ADEnCounter = 0
- $HTEnCounter = 0
- $HTEnCounter2 = 0
- $JSONEnCounter = 0
- $ADEnObjectsCounter = 0
- foreach ($user in $users){
- #Write-Output "Get-ADUser"
- $ADCounter += Measure-Command {
- Get-AdUser $user} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where-Object on original results"
- $ADObjectsCounter += Measure-Command {
- $ADUsers | Where samaccountname -EQ "$user"} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Foreach method with break on original results"
- $ADObjectsForeachbreakCounter += Measure-Command {
- foreach ($aduser in $ADUsers){
- if ($aduser.samaccountname -eq $user){
- $aduser
- break
- }
- }
- } | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Foreach method on original results"
- $ADObjectsForeachCounter += Measure-Command {
- foreach ($aduser in $ADUsers){
- if ($aduser.samaccountname -eq $user){
- $aduser
- }
- }
- } | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where method on original results"
- $ADObjectsWhereCounter += Measure-Command {
- $ADUsers.Where({$_.samaccountname -EQ "$user"})} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where method on original results"
- $ADObjectsWhereFirstCounter += Measure-Command {
- $ADUsers.Where({$_.samaccountname -EQ "$user"},'First',1)} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where-Object on CSV"
- $CSVCounter += Measure-Command {
- $ADUsersCSV | Where samaccountname -EQ "$user"} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where method on CSV"
- $CSVWhereCounter += Measure-Command {
- $ADUsersCSV.Where({$_.samaccountname -EQ "$user"})} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where method on CSV"
- $CSVWhereFirstCounter += Measure-Command {
- $ADUsersCSV.Where({$_.samaccountname -EQ "$user"},'First',1)} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where-Object from JSON"
- $JSONCounter += Measure-Command {
- $ADUsersJSON | Where samaccountname -EQ "$user"} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Foreach with break on JSON"
- $JSONForeachbreakCounter += Measure-Command {
- foreach ($aduser in $ADUsersJSON){
- if ($aduser.samaccountname -eq $user){
- $aduser
- break
- }
- }
- } | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Foreach on JSON"
- $JSONForeachCounter += Measure-Command {
- foreach ($aduser in $ADUsersJSON){
- if ($aduser.samaccountname -eq $user){
- $aduser
- }
- }
- } | select -ExpandProperty TotalMilliSeconds
- #Write-Output "Where-Object on ArrayList"
- $ArrayCounter += Measure-Command {
- $ADusersArray | Where samaccountname -EQ "$user"} | select -ExpandProperty TotalMilliSeconds
- #Write-Output "$(($ADusersHT.gettype()).name)"
- $HTCounter += Measure-Command {
- $ADUsersHT["$user"]} | select -ExpandProperty TotalMilliSeconds
- $ADEnObjectsCounter += (measure-command {$ADUsers | where {$_.samaccountname -eq $user -and $_.enabled -eq $true}}).TotalMilliSeconds
- $JSONEnCounter += (measure-command {foreach ($aduser in $ADUsersJSON){
- if ($aduser.samaccountname -eq $user -and $aduser.Enabled -eq $true){
- $aduser.Enabled
- break
- }
- }}).TotalMilliSeconds
- $HTEnCounter2 += (measure-command {($ADUsersHT[$user]).enabled -eq $true}).TotalMilliSeconds
- $ADEnCounter +=(measure-command {(Get-ADUser $user).enabled -eq $true}).TotalMilliSeconds
- }
- " ======= "
- "ADCounter $ADCounter"
- "ADObjectsCounter $ADObjectsCounter"
- "ADObjectsWhereCounter $ADObjectsWhereCounter"
- "ADObjectsWhereFirstCounter $ADObjectsWhereFirstCounter"
- "ADObjectsForeachCounter $ADObjectsForeachCounter"
- "ADObjectsForeachbreakCounter $ADObjectsForeachbreakCounter"
- "CSVCounter $CSVCounter"
- "CSVWhereCounter $CSVWhereCounter"
- "CSVWhereFirstCounter $CSVWhereFirstCounter"
- "JSONCounter $JSONCounter"
- "JSONForeachbreakCounter $JSONForeachbreakCounter"
- "JSONForeachCounter $JSONForeachCounter"
- "ArrayCounter $ArrayCounter"
- "HTCounter $HTCounter"
- "=="
- "ADEnCounter $ADEnCounter"
- "ADEnObjects $ADEnObjectsCounter"
- "HTEnCounter $HTEnCounter"
- "HTEnCounter2 $HTEnCounter2"
- "JSONEnCounter $JSONEnCounter"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement