Cartwheel.TargetAction.psm1
# # Cartwheel_TargetAction.psm1 # function Test-Target { [OutputType([System.Collections.Hashtable])] [CmdletBinding()] param( [Parameter(Mandatory)] [ValidateSet("Present", "Absent")] [string]$Ensure, [Parameter(Mandatory)] [bool]$testTargetResourceResult, [Parameter(Mandatory)] [AllowEmptyString()] [string]$ItemErr, [Parameter(Mandatory)] [string]$ItemName ) #our return object. default these for now. $info = @{ "ReturnValue" = $false; #True,False "Command" = "Skip"; # Add,Remove,Skip,Error } $modname = $MyInvocation.MyCommand.ModuleName If ($Ensure -eq "Present") { If($testTargetResourceResult -and (-not $ItemErr)) { Write-Verbose "$modname : Item ($ItemName) exists. Expected present" Write-Verbose "$modname Set-TargetResource : (skipping)" $info.ReturnValue = $true $info.Command = "Skip" return $info } Else { if ($ItemErr) { Write-Verbose "$modname : $($ItemErr.exception.message)" $info.ReturnValue = $false $info.Command = "Error" return $info } Write-Verbose "$modname : Item ($ItemName) absent. Expected present" $info.ReturnValue = $false $info.Command = "Add" return $info } } Else { #$Ensure -eq "Absent" If($testTargetResourceResult -and (-not $ItemErr)) { Write-Verbose "$modname : Item ($ItemName) exists. Expected absent" $info.ReturnValue = $false $info.Command = "Remove" return $info } Else { if ($ItemErr) { Write-Verbose "$modname : $($ItemErr.exception.message)" $info.ReturnValue = $false $info.Command = "Error" return $info } Write-Verbose "$modname : Item ($ItemName) absent. Expected absent" Write-Verbose "$modname Set-TargetResource : (skipping)" $info.ReturnValue = $true $info.Command = "Skip" return $info } } } |