Added pscustomobject to hashtable converter
This commit is contained in:
21
functions/private/ConvertTo-Hashtable.ps1
Normal file
21
functions/private/ConvertTo-Hashtable.ps1
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
function ConvertTo-Hashtable {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param (
|
||||||
|
[Parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0
|
||||||
|
)]
|
||||||
|
[ValidateNotNullOrEmpty()]
|
||||||
|
[PSCustomObject]$InputObject
|
||||||
|
)
|
||||||
|
process {
|
||||||
|
$_hashtable = @{}
|
||||||
|
$InputObject | Get-Member -MemberType *Property | Where-Object {
|
||||||
|
$_hashtable.($_.name) = $CustomFields.($_.name)
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Output $_hashtable
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,23 +14,53 @@ function Get-Vlan {
|
|||||||
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
[CmdletBinding(DefaultParameterSetName="NoParams")]
|
||||||
[OutputType([PS.IPAM.Vlan])]
|
[OutputType([PS.IPAM.Vlan])]
|
||||||
param (
|
param (
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByID")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByID"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Id,
|
$Id,
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByNumber")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByNumber"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$Number,
|
$Number,
|
||||||
[parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByL2Domain")]
|
[parameter(
|
||||||
|
Mandatory=$true,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByL2Domain"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[int]
|
[int]
|
||||||
$L2DomainId,
|
$L2DomainId,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="BySubnetObject")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="BySubnetObject"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[PS.IPAM.Subnetwork]
|
[PS.IPAM.Subnetwork]
|
||||||
$SubnetObject,
|
$SubnetObject,
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true,Position=0,ParameterSetName="ByDomainObject")]
|
[parameter(
|
||||||
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true,
|
||||||
|
Position=0,
|
||||||
|
ParameterSetName="ByDomainObject"
|
||||||
|
)]
|
||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[PS.IPAM.Domain]
|
[PS.IPAM.Domain]
|
||||||
$DomainObject
|
$DomainObject
|
||||||
|
|||||||
@@ -126,8 +126,11 @@ function New-Address {
|
|||||||
[ValidateNotNullOrEmpty()]
|
[ValidateNotNullOrEmpty()]
|
||||||
[string]
|
[string]
|
||||||
$Port,
|
$Port,
|
||||||
|
[parameter(
|
||||||
[parameter(Mandatory=$false,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
|
Mandatory=$false,
|
||||||
|
ValueFromPipeline=$true,
|
||||||
|
ValueFromPipelineByPropertyName=$true
|
||||||
|
)]
|
||||||
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
[ValidateScript({ $_ -is [Hashtable] -or $_ -is [PSCustomObject] })]
|
||||||
$CustomFields
|
$CustomFields
|
||||||
)
|
)
|
||||||
@@ -156,10 +159,7 @@ function New-Address {
|
|||||||
|
|
||||||
if ($CustomFields) {
|
if ($CustomFields) {
|
||||||
if ($CustomFields -is [PSCustomObject]) {
|
if ($CustomFields -is [PSCustomObject]) {
|
||||||
$_customFields = @{};
|
$_customFields = ConvertTo-Hashtable -InputObject $CustomFields
|
||||||
$CustomFields | Get-Member -MemberType *Property | Where-Object {
|
|
||||||
$_customFields.($_.name) = $CustomFields.($_.name)
|
|
||||||
}
|
|
||||||
} else { $_customFields = $CustomFields }
|
} else { $_customFields = $CustomFields }
|
||||||
|
|
||||||
$_body = $_body + $_customFields
|
$_body = $_body + $_customFields
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
FunctionsToExport = @(
|
FunctionsToExport = @(
|
||||||
'Assign-Tag',
|
'Assign-Tag',
|
||||||
|
'Close-Session',
|
||||||
'New-Session',
|
'New-Session',
|
||||||
'Get-Address',
|
'Get-Address',
|
||||||
'Get-FirstFreeIP',
|
'Get-FirstFreeIP',
|
||||||
|
|||||||
Reference in New Issue
Block a user