/Set-FailedPesterTests.ps1 Secret
Created
November 21, 2017 09:44
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
Author: I. Strachan | |
Version: | |
Version History: | |
Purpose: Set ADUser attributes of failed tests | |
#> | |
[CmdletBinding(SupportsShouldProcess = $True)] | |
Param( | |
$csvFile = 'D:\Scripts\ps1\source\csv\FailedTests.csv' | |
) | |
$FailedTests = Import-Csv -Path $csvFile -Delimiter "`t" -Encoding UTF8 | |
#Get Set-ADUser Parameters | |
$setADUserParameters = (Get-Command Set-ADUser).ParameterSets.Parameters.Where{ $_.IsDynamic -eq $true} | Select-Object -ExpandProperty Name | |
#Get User Property | |
$FailedTests | | |
Foreach-object{ | |
#Set Expected to null if <not set> | |
$Expected = @{$true = $null; $false = $_.Expected}[$_.Expected -eq '<not set>'] | |
If ($setADUserParameters.Contains($_.Property)){ | |
$paramSetADUser = @{ | |
Identity = $_.SamAccountName | |
$_.Property = $Expected | |
} | |
Set-ADUser @paramSetADUser | |
} | |
else{ | |
if($Expected){ | |
Set-ADUser -Identity $($_.SamAccountName) -Replace @{$_.Property = $Expected} | |
} | |
else{ | |
Set-ADUser -Identity $($_.SamAccountName) -Clear $($_.Property) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment