How do I write a PowerShell cmdlet to take either a HashTable or a PODO for input?
-
31-10-2019 - |
Вопрос
I have a powershell module that wraps around some web services. The web services take complex Plain Old Dot Net Objects (PODOs) and I have been using HashTables as in cmdlet parameters and New-Object MyPODO -Property $MyHashTable to transform the hashtable into the request object like so
function Get-Stuff ([HashTable]$WhatStuff) {
$service = New-ServiceProxy . . . .
$request = New-Object GetStuffRequest -Property $WhatStuff;
return $service.GetStuff($request);
$response;
}
However, sometimes I have a cmdlet whose response object can directly become a request object like so:
function Find-Stuff ([HashTable]$KindaStuff) {
$service = New-ServiceProxy . . . .
$request = New-Object GetStuffRequest -Property $KindaStuff;
return $service.SearchStuff($request);
}
Is there some sort of way to decorate the $WhatStuff parameter to accept either a HashTable or a PODO of a particular type?
Нет правильного решения
Не связан с StackOverflow