Public/Update-TMTaskAsset.ps1
Function Update-TMTaskAsset { param( [Parameter(Mandatory = $false)][PSObject][AllowNull()]$AssetUpdates = $null, [Parameter(Mandatory = $false)][String][AllowNull()]$Field = $null, [Parameter(Mandatory = $false)][PSObject][AllowNull()]$Value = $null ) ## Ensure that there is a TM Asset Updates global Array use # if (-not $global:TMAssetUpdates) { $global:TMAssetUpdates = [System.Collections.ArrayList]@() } if (-not $global:TMAssetUpdates) { $global:TMAssetUpdates = [pscustomobject]@{} } ## Allow for providing in a full Hashtable of updates if ($AssetUpdates) { $AssetUpdates.PSObject.Properties | ForEach-Object { $global:TMAssetUpdates | Add-Member -NotePropertyName $_.Name -NotePropertyValue $_.value -Force Write-Host "Updating TM Asset Field: " -NoNewline Write-Host $_.Name -NoNewline -ForegroundColor Green Write-Host ' with value: ' -NoNewline if ($_.Value.GetType() -in @('Hashtable', 'PSObject', 'PSCustomObject')) { Write-Host ($_.Value | ConvertTo-Json -Depth 10) -ForegroundColor Yellow } else { Write-Host $_.Value -ForegroundColor Yellow } } } ## Allow for adding in a single field and value. if ($Field) { $global:TMAssetUpdates | Add-Member -NotePropertyName $Field -NotePropertyValue $Value -Force Write-Host "Updating TM Asset Field: " -NoNewline Write-Host $Field -NoNewline -ForegroundColor Cyan Write-Host ' with value: ' -NoNewline if ($Null -eq $Value) { Write-Host "NULL - Clearing JSON field association" -ForegroundColor Yellow } else { if ($Value.GetType() -in @('Hashtable', 'PSObject', 'PSCustomObject')) { Write-Host ($Value | ConvertTo-Json -Depth 10) -ForegroundColor Yellow } else { Write-Host $Value -ForegroundColor Yellow } } } } |