Skip to content

Instantly share code, notes, and snippets.

@evetsleep
Created February 19, 2019 16:00
Show Gist options
  • Save evetsleep/f97d85ffbe92f8542f4f924f038e45b6 to your computer and use it in GitHub Desktop.
Save evetsleep/f97d85ffbe92f8542f4f924f038e45b6 to your computer and use it in GitHub Desktop.
$testTitle = 'stuff'
$results = New-Object System.Collections.Generic.List[PSCUstomObject]
0..99 | ForEach-Object {
# Used to store the timing of the query and the update times.
$testResults = [PSCustomObject]@{
Test1Query = $Null
Test1UpdateAvgMS = $Null
Test2Query = $Null
Test2UpdateAvgMS = $Null
}
<#
Query for all users whose name starts with u while storing them
as their natural object type in $users. Then iterate over them
and those who have an employeeId write to their title.
#>
$testResults.Test1Query = (Measure-Command -Expression {
$users = Get-ADUser -Filter "name -like 'u*'" -Properties employeeId
}).Milliseconds
$test1Stats = New-Object System.Collections.Generic.List[object]
foreach ($user in $users) {
$test1Update = Measure-Command {
if ($user.employeeId) {
Set-ADUser -Identity $user.distinguishedname -Title $testTitle
}
}
$test1Stats.Add($test1Update)
}
$testResults.Test1UpdateAvgMS = ($test1Stats | Measure-Object -Property TotalMilliseconds -Average).Average
<#
Query for all users whose name starts with u and storing the resulting
users as PSCustomObjects. Then iterate over them and those who
have an employeeId write to their title.
#>
$testResults.Test2Query = (Measure-Command -Expression {
$users = New-Object System.Collections.Generic.List[PSCustomObject]
Get-ADUser -Filter "name -like 'u*'" -Properties employeeId | ForEach-Object {
$users.Add([PSCustomObject]@{
distinguishedName = $PSItem.distinguishedname
sAMAccountName = $PSItem.sAMAccountname
employeeId = $PSItem.employeeId
})
}
}).Milliseconds
$test2Stats = New-Object System.Collections.Generic.List[object]
foreach ($user in $users) {
$test2Update = Measure-Command {
if ($user.employeeId) {
Set-ADUser -Identity $user.distinguishedname -Title $testTitle
}
}
$test2Stats.Add($test2Update)
}
$testResults.Test2UpdateAvgMS = ($test2Stats | Measure-Object -Property TotalMilliseconds -Average).Average
$results.Add($testResults)
}
[PSCustomObject]@{
Tests = $results.count
Test1Query = ($results | Measure-Object -Property Test1Query -Average).Average
Test1AvgMS = ($results | Measure-Object -Property Test1UpdateAvgMS -Average).Average
Test2Query = ($results | Measure-Object -Property Test2Query -Average).Average
Test2AvgMS = ($results | Measure-Object -Property Test2UpdateAvgMS -Average).Average
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment