How do I write a PowerShell cmdlet to take either a HashTable or a PODO for input?

StackOverflow https://stackoverflow.com/questions/7433673

  •  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?

올바른 솔루션이 없습니다

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top