InfobloxCmdlets.psm1

#Variables
#Helper Functions
Function ConvertTo-PTRName {
    Param(
        [Parameter(Mandatory=$True,ValueFromPipeline=$True)]
        [ipaddress]$IPAddress
    )
    BEGIN{}    
    PROCESS{
        $Octets = $IPAddress.IPAddressToString.split('.')
        $name = "$($octets[3]).$($octets[2]).$($octets[1]).$($octets[0]).in-addr.arpa"
        return $name
    }
    END{}
}
Function ConvertFrom-PTRName {
    Param(
        [Parameter(mandatory=$True,ValueFromPipeline=$True)]
        [String]$PTRName
    )
    BEGIN{}
    PROCESS{
        $Octets = $PTRName.split('.')
        [IPAddress]$IPAddress = "$($octets[3]).$($octets[2]).$($octets[1]).$($octets[0])"
        return $IPAddress
    }
    END{}
}
Function ConvertTo-ExtAttrsArray {
    Param (
        [Parameter(ValueFromPipeline=$True)]
        [Object]$extattrs
    )
    BEGIN{}
    PROCESS{
        If ($Extattrs) {
            $ExtAttrList = $Extattrs | get-member | where-object{$_.MemberType -eq 'NoteProperty'}
            Foreach ($ExtAttr in $ExtAttrList){
                $objExtAttr = New-object PSObject -Property @{
                    Name = $Extattr.Name
                }
                Foreach ($property in $($ExtAttrs.$($Extattr.Name) | get-member | where-object{$_.membertype -eq 'noteproperty'})) {
                    $objExtAttr | Add-Member -MemberType NoteProperty -name $property.Name -Value $($Extattrs.$($extattr.name).$($property.name))
                }
                $objextattr
            }
        } else {
            return $Null
        }
    }
    END{}
}
Function ConvertFrom-ExtAttrsArray {
    Param (
        [Parameter(ValueFromPipeline=$True)]
        [object]$ExtAttrib
    )
    BEGIN{}
    PROCESS{
        $objextattr = New-Object psobject -Property @{}
        Foreach ($extattr in $extattrib){
            $Value = new-object psobject -Property @{value=$ExtAttrib.value}
            $objextattr | Add-Member -MemberType NoteProperty -Name $($ExtAttrib.Name) -Value $Value
        }
        $objextattr
    }
    END{}
}
Function SearchstringToIBQuery {
    param ($SearchString)
    $Words = $Searchstring.split(' ')
    $property = $words[0]
    $Operator = $words[1]
    $Value = $words[2..$($words.length -1)] -join ' ' -replace "`"" -replace "`'"
    If ($operator -eq '-eq'){$iboperator = ':='}
    If ($operator -eq '-like'){$iboperator = '~:='}
    $IBQueryString = "*$property$iboperator$value&"
    return $IBQueryString
}
Class IB_ReferenceObject {
    #properties
    [String]$_ref
    #methods
    
    [String] ToString(){
        return $this._ref
    }
    static [IB_ReferenceObject] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [string]$_ref
    ) {
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_ReferenceObject]::New($return._ref)
        } else {
            return $null
        }
    }
   hidden [String] Delete(
           [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion
   ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $return = Invoke-RestMethod -Uri $URIString -Method Delete -WebSession $Session
        return $return
    }
    #constructors
    IB_ReferenceObject(){}
    IB_ReferenceObject(
        [String]$_ref
    ){
        $this._ref = $_ref
    }
}
Class IB_DNSARecord : IB_ReferenceObject {
    ##Properties
    [String]$Name
    [IPAddress]$IPAddress
    [String]$Comment
    [String]$View
    [uint32]$TTL
    [bool]$Use_TTL
    [Object]$ExtAttrib

#region Methods
    #region Create method
    static [IB_DNSARecord] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$view,
        [uint32]$TTL,
        [bool]$Use_TTL
    ){
        $URIString = "https://$Gridmaster/wapi/$Wapiversion/record:a"
        $BodyHashTable = @{name=$Name}
        $bodyhashtable += @{ipv4addr=$IPAddress}
        $bodyhashtable += @{comment=$comment}
        If ($view){$bodyhashtable += @{view = $view}}

        If ($Use_TTL){
            $BodyHashTable+= @{ttl = $TTL}
            $BodyHashTable+= @{use_ttl = $use_ttl}
        }

        $return = Invoke-RestMethod -Uri $URIString -Method Post -Body $BodyHashTable -WebSession $Session
        If ($return) {
            return [IB_DNSARecord]::Get($gridmaster,$Session,$WapiVersion,$return)
        }else {
            return $Null
        }
        
    }
    #endregion
    #region Get methods
        static [IB_DNSARecord] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,ipv4addr,comment,view,ttl,use_ttl"
        $URIString = "https://$Gridmaster/wapi/$Wapiversion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            If ($return.ipv4addr.length -eq 0){$return.ipv4addr = $Null}
            return [IB_DNSARecord]::New($return.name,
                                        $return.ipv4addr,
                                        $return.comment,
                                        $return._ref,
                                        $return.view,
                                        $return.TTL,
                                        $return.use_TTL,
                                        $($Return.extattrs | ConvertTo-ExtAttrsArray))
        } else {
            return $null
        }
    }

    static [IB_DNSARecord[]] Get(
         [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [String]$Zone,
        [String]$View,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,ipv4addr,comment,view,ttl,use_ttl"
        $URI = "https://$Gridmaster/wapi/$Wapiversion/record:a?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($IPAddress){
            $URI += "ipv4addr=$($ipaddress.IPAddressToString)&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
        If ($Zone){
            $URI += "zone=$Zone&"
        }
        If ($View){
            $URI += "view=$view&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
            If ($item.ipv4addr.length -eq 0){$item.ipv4addr = $Null}
            [IB_DNSARecord]::New($item.name,
                                            $item.ipv4addr,
                                            $item.comment,
                                            $item._ref,
                                            $item.view,
                                            $item.TTL,
                                            $item.use_TTL,
                                            $($item.extattrs | convertTo-ExtAttrsArray))
        }
        return $output
    }
    #endregion
    #region Set method
    hidden [void]Set(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [uint32]$ttl,
        [bool]$use_ttl
    ){
        $URIString = "https://$Gridmaster/wapi/$Wapiversion/$($this._ref)"
        $bodyHashTable = $null
        $bodyHashTable+=@{ipv4addr=$($IPAddress.IPAddressToString)}
        $bodyHashTable+=@{comment=$comment}
        $bodyHashTable+=@{use_ttl=$use_ttl}
        If ($use_ttl){
            $bodyHashTable+=@{ttl=$ttl}
        } else {
            $bodyHashTable += @{ttl=0}
        }
        If ($bodyHashTable){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $($bodyHashTable | ConvertTo-Json) -ContentType application/json -WebSession $Session
            if ($return) {
                $this._ref = $return
                $this.ipaddress = $IPAddress
                $this.comment = $Comment
                $this.use_ttl = $use_ttl
                If ($use_ttl){
                    $this.ttl = $ttl
                } else {
                    $this.ttl = $null
                }
            }
        }
    }
    #endregion
    #region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$Wapiversion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSARecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
    #region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$Wapiversion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSARecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
#endregion
#region Constructors
    IB_DNSARecord(
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$_ref,
        [String]$view,
        [uint32]$ttl,
        [bool]$use_ttl,
        [Object]$ExtAttrib
    ){
        $this.Name        = $Name
        $this.IPAddress   = $IPAddress
        $this.Comment     = $Comment
        $this._ref        = $_ref
        $this.view        = $view
        $this.TTL         = $ttl
        $this.use_ttl     = $use_ttl
        $this.extattrib   = $ExtAttrib
    }
#endregion
}
Class IB_DNSCNameRecord : IB_ReferenceObject {
    ##Properties
    [String]$Name
    [String]$canonical
    [String]$Comment
    [String]$view
    [uint32]$TTL
    [bool]$Use_TTL
    [Object]$ExtAttrib

#region Methods
    #region Create method
    static [IB_DNSCNameRecord] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$canonical,
        [String]$Comment,
        [String]$view,
        [uint32]$TTL,
        [bool]$Use_TTL

    ){
        
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/record:cname"
        $BodyHashTable = @{name=$Name}
        $bodyhashtable += @{canonical=$Canonical}
        $bodyhashtable += @{comment=$comment}
        If ($View){$bodyhashtable += @{view = $view}}
        If ($use_ttl){
            $BodyHashTable += @{ttl = $ttl}
            $BodyHashTable += @{use_ttl = $use_ttl}
        }
        $return = Invoke-RestMethod -Uri $URIString -Method Post -Body $BodyHashTable -WebSession $Session
        If ($Return) {
            return [IB_DNSCNameRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
        } else {
            return $Null
        }
    }
    #endregion
    #region Get methods
    static [IB_DNSCNameRecord] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,canonical,comment,view,ttl,use_ttl"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($return) {
            return [IB_DNSCNameRecord]::New($return.Name,
                                            $return.canonical,
                                            $return.comment,
                                            $return._ref,
                                            $return.view,
                                            $return.ttl,
                                            $return.use_ttl,
                                            $($Return.extattrs | ConvertTo-ExtAttrsArray))
        } else {
            return $Null
        }
    }


    static [IB_DNSCNameRecord[]] Get(
         [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
       [String]$Name,
        [String]$Canonical,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [String]$Zone,
        [String]$View,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,canonical,comment,view,ttl,use_ttl"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/record:cname?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($Canonical){
            $URI += "canonical$operator$Canonical&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
        If ($Zone){
            $URI += "zone=$Zone&"
        }
        If ($View){
            $URI += "view=$view&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
                [IB_DNSCNameRecord]::New($item.Name,
                                                    $item.canonical,
                                                    $item.comment,
                                                    $item._ref,
                                                    $item.view,
                                                    $item.ttl,
                                                    $item.use_ttl,
                                                    $($item.extattrs | ConvertTo-ExtAttrsArray))
        }
        return $output
    }
    #endregion
    #region Set method
    hidden [Void] Set(
          [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$canonical,
        [String]$Comment,
        [uint32]$TTL,
        [bool]$Use_TTL

    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyHashTable = $null
        $bodyHashTable+=@{canonical=$canonical}
        $bodyHashTable+=@{comment=$comment}
        $bodyHashTable+=@{use_ttl=$use_ttl}
        If ($use_ttl){
            $bodyHashTable+=@{ttl=$ttl}
        } else {
            $bodyHashTable += @{ttl=0}
        }

        If ($bodyHashTable){
            $return = Invoke-RestMethod -Uri $URIString -Method Put -Body $($bodyHashTable | ConvertTo-Json) -ContentType application/json -WebSession $Session
            if ($return) {
                $this._ref = $return
                $this.canonical = $canonical
                $this.comment = $Comment
                $this.use_ttl = $use_ttl
                If ($use_ttl){
                    $this.ttl = $ttl
                } else {
                    $this.ttl = $null
                }
            }        
        }
    }
    #endregion
    #region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSCNameRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
    #region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSCNameRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
#endregion

#region Constructors
    IB_DNSCNameRecord(
        [String]$Name,
        [String]$canonical,
        [String]$Comment,
        [String]$_ref,
        [String]$view,
        [uint32]$TTL,
        [bool]$Use_TTL,
        [Object]$ExtAttrib
    ){
        $this.Name        = $Name
        $this.canonical   = $canonical
        $this.Comment     = $Comment
        $this._ref        = $_ref
        $this.view        = $view
        $this.TTL         = $TTL
        $this.Use_TTL     = $use_ttl
        $this.extattrib   = $ExtAttrib
    }

#endregion
}
Class IB_DNSPTRRecord : IB_ReferenceObject {
    ##Properties
    [IPAddress]$IPAddress
    [String]$PTRDName
    [String]$Name
    [String]$Comment
    [String]$view
    [uint32]$TTL
    [bool]$Use_TTL
    [Object]$ExtAttrib

#region Methods
    #region Create method
    static [IB_DNSPTRRecord] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$PTRDName,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$view,
        [uint32]$TTL,
        [bool]$Use_TTL

    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/record:ptr"
        $BodyHashTable = @{ipv4addr=$($IPAddress.IPAddressToString)}
        $bodyhashtable += @{ptrdname=$PTRDName}
        $bodyhashtable += @{comment=$comment}
        If ($View){$bodyhashtable += @{view = $view}}
        If ($use_TTL){
            $BodyHashTable+= @{ttl=$ttl}
            $bodyhashtable+= @{use_ttl=$use_ttl}
        }
        $return = Invoke-RestMethod -Uri $URIString -Method Post -Body $BodyHashTable -WebSession $Session
        If ($Return) {
            return [IB_DNSPTRRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
        } else {
            return $Null
        }
    }
    #endregion
    #region Get methods
    static [IB_DNSPTRRecord] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,ptrdname,ipv4addr,comment,view,ttl,use_ttl"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            If ($return.ipv4addr.length -eq 0){$return.ipv4addr = $Null}
            return [IB_DNSPTRRecord]::New($return.ptrdname,
                                          $return.ipv4addr,
                                          $return.Name,
                                          $return.comment,
                                          $return._ref,
                                          $return.view,
                                          $return.ttl,
                                          $return.use_ttl,
                                          $($return.extattrs | ConvertTo-ExtAttrsArray))
        } else {
            return $Null
        }
    }

    static [IB_DNSPTRRecord[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$PTRdname,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [String]$Zone,
        [String]$View,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,ptrdname,ipv4addr,comment,view,ttl,use_ttl"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/record:ptr?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($IPAddress){
            $URI += "ipv4addr=$($ipaddress.IPAddressToString)&"
        }
        If ($PTRdname){
            $URI += "ptrdname$operator$PTRdname&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
        If ($Zone){
            $URI += "zone=$Zone&"
        }
        If ($View){
            $URI += "view=$view&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
                If ($item.ipv4addr.length -eq 0){$item.ipv4addr = $Null}
                [IB_DNSPTRRecord]::New($item.ptrdname,
                                                  $item.ipv4addr,
                                                  $item.name,
                                                  $item.comment,
                                                  $item._ref,
                                                  $item.view,
                                                  $item.ttl,
                                                  $item.use_ttl,
                                                  $($item.extattrs | ConvertTo-ExtAttrsArray))
        }
        return $output
    }
    #endregion
    #region Set method
    hidden [Void] Set(
         [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$PTRDName,
        [String]$Comment,
        [uint32]$ttl,
        [bool]$use_ttl
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyHashTable = $null
        $bodyHashTable+=@{ptrdname=$PTRDName}
        $bodyHashTable+=@{comment=$comment}
        $bodyHashTable+=@{use_ttl=$use_ttl}
        If ($use_ttl){
            $bodyHashTable+=@{ttl=$ttl}
        } else {
            $bodyHashTable += @{ttl=0}
        }

        If ($bodyHashTable){
            $return = Invoke-RestMethod -Uri $URIString -Method Put -Body $($bodyHashTable | ConvertTo-Json) -ContentType application/json -WebSession $Session
            if ($return) {
                $this._ref = $return
                $this.ptrdname = $PTRDName
                $this.comment = $Comment
                $this.use_ttl = $use_ttl
                If ($use_ttl){
                    $this.ttl = $ttl
                } else {
                    $this.ttl = $null
                }

            }
        }
    }
    #endregion
    #region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSPTRRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
    #region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_DNSPTRRecord]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
#endregion
#region Constructors
    IB_DNSPTRRecord(
        [String]$PTRDName,
        [IPAddress]$IPAddress,
        [String]$Name,
        [String]$Comment,
        [String]$_ref,
        [String]$view,
        [uint32]$TTL,
        [bool]$Use_ttl,
        [Object]$ExtAttrib
    ){
        $this.PTRDName    = $PTRDName
        $this.ipaddress   = $IPAddress
        $this.Name        = $Name
        $this.Comment     = $Comment
        $this._ref        = $_ref
        $this.view        = $view
        $this.ttl         = $TTL
        $this.Use_TTL     = $Use_ttl
        $this.extattrib   = $ExtAttrib
    }
#endregion
}

Class IB_ExtAttrsDef : IB_ReferenceObject {
    ##Properties
    [String]$Name
    [String]$Type
    [String]$Comment
    [String]$DefaultValue
#region Methods
    [String] ToString () {
        return $this.name
    }

    #region Create method
    static [IB_ExtAttrsDef] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Type,
        [String]$Comment,
        [String]$DefaultValue
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/extensibleattributedef"
        $BodyHashTable = @{name=$Name}
        $bodyhashtable += @{type=$Type.ToUpper()}
        $bodyhashtable += @{comment=$comment}
        if ($defaultvalue){$bodyhashtable += @{default_value=$DefaultValue}}
        $return = Invoke-RestMethod -Uri $URIString -Method Post -Body $BodyHashTable -WebSession $Session
        If ($return) {
            return [IB_ExtAttrsDef]::Get($gridmaster,$Session,$WapiVersion,$return)
        }else {
            return $Null
        }
        
    }
    #endregion
    #region Get methods
        static [IB_ExtAttrsDef] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "name,comment,default_value,type"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_ExtAttrsDef]::New($return.name,$return.type,$return.comment,$return.default_value,$return._ref)
        } else {
            return $null
        }
    }

    static [IB_ExtAttrsDef[]] Get(
         [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Type,
        [String]$Comment,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "name,comment,default_value,type"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/extensibleattributedef?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($Type){
            $URI += "type=$($Type.ToUpper())&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
            [IB_ExtAttrsDef]::New($Item.name,$Item.type,$Item.comment,$Item.default_value,$Item._ref)
        }
        return $output
    }
    #endregion
    #region Set method
    hidden [void]Set(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Type,
        [String]$Comment,
        [String]$DefaultValue
    )
    {
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyHashTable = $null
        $bodyHashTable+=@{name=$Name}
        $bodyHashTable+=@{type=$Type.ToUpper()}
        $bodyHashTable+=@{comment=$comment}
        $bodyHashTable+=@{default_value=$DefaultValue}
        If ($bodyHashTable){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $($bodyHashTable | ConvertTo-Json) -ContentType application/json -WebSession $Session
            if ($return) {
                $this._ref = $return
                $this.type = $Type
                $this.comment = $Comment
                $this.defaultvalue = $DefaultValue
            }
        }
    }
    #endregion
#endregion
#region Constructors
    IB_ExtAttrsDef(
        [String]$Name,
        [String]$Type,
        [String]$Comment,
        [String]$DefaultValue,
        [String]$_ref
    ){
        $this.Name         = $Name
        $this.Comment      = $Comment
        $this._ref         = $_ref
        $this.type         = $Type
        $this.DefaultValue = $DefaultValue
    }
#endregion
}
Class IB_FixedAddress : IB_ReferenceObject {
    ##Properties
    [String]$Name
    [IPAddress]$IPAddress
    [String]$Comment
    [String]$NetworkView
    [String]$MAC
    [Object]$ExtAttrib
#region Methods
#region Create method
    static [IB_FixedAddress] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$NetworkView,
        [String]$MAC
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/fixedaddress"
        $bodyhashtable = @{ipv4addr=$IPAddress}
        $BodyHashTable += @{name=$Name}
        $bodyhashtable += @{comment=$comment}
        If ($networkview){$bodyhashtable += @{network_view = $NetworkView}}
        $BodyHashTable += @{mac = $MAC}
        If (($MAC -eq '00:00:00:00:00:00') -or ($MAC.Length -eq 0)){
            $bodyHashTable += @{match_client='RESERVED'}
        } else {
            $bodyHashTable += @{match_client='MAC_ADDRESS'}
        }

        $return = Invoke-RestMethod -Uri $URIString -Method Post -Body $BodyHashTable -WebSession $Session
        return [IB_FixedAddress]::Get($gridmaster,$Session,$WapiVersion,$return)
        
    }
    #endregion
    #region Get methods
    static [IB_FixedAddress] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,ipv4addr,comment,network_view,mac"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_FixedAddress]::New($return.name,
                                          $return.ipv4addr,
                                          $return.comment,
                                          $return._ref,
                                          $return.network_view,
                                          $return.mac,
                                          $($return.extattrs | Convertto-ExtAttrsArray))
        } else {
            return $Null
        }
    }
    static [IB_FixedAddress[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [IPAddress]$IPAddress,
        [String]$MAC,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [String]$NetworkView,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,ipv4addr,comment,network_view,mac"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/fixedaddress?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($IPAddress){
            $URI += "ipv4addr=$($IPAddress.IPAddressToString)&"
        }
        If ($MAC){
            $URI += "mac=$mac&"
        }
        If ($Comment){
            $URI += "comment$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
        If ($NetworkView){
            $URI += "network_view=$NetworkView&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
            [IB_FixedAddress]::New($item.name,
                                              $item.ipv4addr,
                                              $item.comment,
                                              $item._ref,
                                              $item.network_view,
                                              $item.mac,
                                              $($item.extattrs | convertto-extAttrsArray))
        }
        return $output
    }
    #endregion
    #region Set method
    hidden [Void] Set(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Comment,
        [String]$MAC
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyHashTable = $null
        $bodyHashTable+=@{name=$Name}
        $bodyHashTable+=@{comment=$comment}
        $bodyHashTable+=@{mac=$MAC}
        If ($MAC -eq "00:00:00:00:00:00"){
            $bodyHashTable+=@{match_client='RESERVED'}
        } else {
            $bodyHashTable+=@{match_client='MAC_ADDRESS'}
        }
        If ($bodyHashTable){
            $return = Invoke-RestMethod -Uri $URIString -Method Put -Body $($bodyHashTable | ConvertTo-Json) -ContentType application/json -WebSession $Session
            if ($return) {
                $this._ref = $return
                $this.name = $Name
                $this.comment = $Comment
                $this.MAC = $MAC
            }
        }
    }
    #endregion
    #region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_FixedAddress]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
    #region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_FixedAddress]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
    #endregion
#endregion
#region Constructors
    IB_FixedAddress(
        [String]$Name,
        [IPAddress]$IPAddress,
        [String]$Comment,
        [String]$_ref,
        [String]$NetworkView,
        [String]$MAC,
        [Object]$ExtAttrib
    ){
        $this.Name         = $Name
        $this.IPAddress    = $IPAddress
        $this.Comment      = $Comment
        $this._ref         = $_ref
        $this.networkview  = $NetworkView
        $this.MAC          = $MAC
        $this.ExtAttrib    = $ExtAttrib
    }
#endregion
}
Class IB_lease : IB_ReferenceObject {
    ##Properties
    [String]$Name
    [String]$IPAddress
    [String]$MAC
    [String]$NetworkView
    [String]$Network
#region Methods
    #region Get methods
    static [IB_lease] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "client_hostname,address,network_view,hardware,network"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_lease]::New($return.client_hostname,
                                          $return.address,
                                          $return._ref,
                                          $return.network_view,
                                          $return.hardware,
                                          $return.network
            )
        } else {
            return $Null
        }
    }
    static [IB_lease[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$IPAddress,
        [String]$MAC,
        [String]$NetworkView,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "client_hostname,address,network_view,hardware,network,starts"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/lease?"
        If ($Strict){$Operator = "="} else {$Operator = "~="}
        If ($IPAddress){
            $URI += "address$operator$IPAddress&"
        }
        If ($MAC){
            $URI += "hardware$operator$MAC&"
        }
        If ($Name){
            $URI += "client_hostname$operator$Name"
        }
        If ($NetworkView){
            $URI += "network_view=$NetworkView&"
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
            [IB_lease]::New($item.client_hostname,
                                        $item.address,
                                        $item._ref,
                                        $item.network_view,
                                        $item.hardware,
                                        $item.network
                                        )
        }
        return $output
    }
    #endregion
#endregion
#region Constructors
    IB_lease(
        [String]$Name,
        [String]$IPAddress,
        [String]$_ref,
        [String]$NetworkView,
        [String]$MAC,
        [String]$Network
    ){
        $this.Name         = $Name
        $this.IPAddress    = $IPAddress
        $this._ref         = $_ref
        $this.networkview  = $NetworkView
        $this.MAC          = $MAC
        $this.Network      = $Network
    }
#endregion
}
Class IB_Network : IB_ReferenceObject {
    ##Properties
    [String]$Network
    [String]$NetworkView
    [String]$NetworkContainer
    [String]$Comment
    [Object]$ExtAttrib
#region Create Method
    static [IB_Network] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Network,
        [String]$NetworkView,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/network"
        $bodyhashtable = @{network=$Network}
        If ($comment){$bodyhashtable += @{comment=$Comment}}
        If ($NetworkView){$bodyhashtable += @{network_view = $NetworkView}}
        $return = Invoke-RestMethod -uri $URIString -Method Post -Body $bodyhashtable -WebSession $Session
        return [IB_Network]::Get($gridmaster,$Session,$WapiVersion,$return)
    }
#region Get Methods
    static [IB_Network] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ){
        $ReturnFields = "extattrs,network,network_view,network_container,comment"
        $URIstring = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $Return = Invoke-RestMethod -Uri $URIstring -WebSession $Session
        If ($Return){
            return [IB_Network]::New($Return.Network,
                                         $return.Network_View,
                                         $return.Network_Container,
                                         $return.Comment,
                                         $($return.extattrs | convertto-ExtAttrsArray),
                                         $return._ref
            )
        } else {
            return $Null
        }
    }
    static [IB_Network[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Network,
        [String]$NetworkView,
        [String]$NetworkContainer,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,network,network_view,network_container,comment"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/network?"
        If ($Strict){$Operator = "="} else {$Operator = "~="}
        If ($Network){
            $URI += "network$Operator$Network&"
        }
        If ($NetworkView){
            $URI += "network_view=$Networkview&"
        }
        If ($NetworkContainer){
            $URI += "network_container=$NetworkContainer&"
        }
        If ($comment){
            $URI += "comment`:$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringtoIBQuery -searchstring $ExtAttribFilter
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -Uri $URI -WebSession $Session
        [array]$output = Foreach ($Item in $Return){
            [IB_Network]::New($item.Network,
                                         $item.Network_View,
                                         $item.Network_Container,
                                         $item.Comment,
                                         $($item.extattrs | convertto-ExtAttrsArray),
                                         $item._ref
            )
        }
        return $Output
    }
#region Set Method
    hidden [void]Set (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyhashtable = @{comment=$Comment}
        If ($bodyhashtable){
            $return = Invoke-RestMethod -uri $URIString -method Put -body $($bodyhashtable | convertto-json) -contenttype application/json -WebSession $Session
            If ($return) {
                $this._ref = $return
                $this.comment = $Comment
            }
        }
    }
#region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_Network]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
#region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_Network]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
#region NextAvailableIP method
    hidden [String[]] GetNextAvailableIP (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String[]]$Exclude,
        [uint32]$Count
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)?_function=next_available_ip"
        $bodyhashtable = $null
        if ($count){$bodyhashtable += @{num = $count}}
        If ($Exclude){$bodyhashtable += @{exclude = $Exclude}}
        If ($bodyhashtable){
            return Invoke-RestMethod -uri $URIString -method Post -body $($bodyhashtable | convertto-json) -contenttype application/json -WebSession $Session
        } else {
            return $Null
        }
    }
#region Constructors
    IB_Network(
        [String]$Network,
        [String]$NetworkView,
        [String]$NetworkContainer,
        [String]$Comment,
        [object]$ExtAttrib,
        [String]$_ref
    ){
        $this.Network          = $Network
        $this.NetworkView      = $NetworkView
        $this.NetworkContainer = $NetworkContainer
        $this.Comment          = $Comment
        $this.ExtAttrib        = $ExtAttrib
        $this._ref             = $_ref
    }
}
Class IB_networkview : IB_ReferenceObject {
    ##Properties
    [String]$name
    [bool]$is_default
    [String]$Comment
    [Object]$ExtAttrib
    ##methods
    [String] ToString () {
        return $this.name
    }
    static [IB_NetworkView] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/networkview"
        $bodyhashtable = @{name=$Name}
        If ($Comment){$bodyhashtable += @{comment=$Comment}}
        $Return = Invoke-RestMethod -uri $URIString -Method Post -body $bodyhashtable -WebSession $Session
        return [IB_NetworkView]::Get($gridmaster,$Session,$WapiVersion,$return)
    }
    static [IB_networkview] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,is_default,comment"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_networkview]::New($Return.name,
                                         $Return.is_default, 
                                         $Return.comment, 
                                         $Return._ref, 
                                         $($return.extattrs | ConvertTo-ExtAttrsArray))
        } else {
            return $Null
        }
                
    }
    static [IB_networkview[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Is_Default,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,is_default,comment"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/networkview?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($Is_Default){
            $URI += "is_default=$Is_Default&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
         If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
       If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
                [IB_networkview]::New($item.name,
                                                 $Item.is_default,
                                                 $item.comment,
                                                 $item._ref,
                                                 $($item.extattrs | ConvertTo-ExtAttrsArray))
        }
        return $output
    }
#region Set Method
    hidden [void]Set (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyhashtable = $Null
        $bodyhashtable += @{name=$Name}
        $bodyhashtable += @{comment=$Comment}
        If ($bodyhashtable){
            $return = Invoke-RestMethod -uri $URIString -method Put -body $($bodyhashtable | convertto-json) -contenttype application/json -WebSession $Session
            If ($return) {
                $this._ref = $return
                $this.name = $Name
                $this.comment = $Comment
            }
        }
    }
    ##constructors
    #These have to exist in order for the List method to create the object instance
    IB_networkview(
        [String]$name,
        [bool]$is_default,
        [string]$comment,
        [string]$_ref,
         [Object]$ExtAttrib
   ){
        $this.name       = $name
        $this.is_default = $is_default
        $this.Comment    = $comment
        $this._ref       = $_ref
        $this.extattrib  = $ExtAttrib
    }
}
Class IB_View : IB_ReferenceObject {
    ##Properties
    [String]$name
    [bool]$is_default
    [String]$Comment
    [Object]$ExtAttrib
    ##methods
    [String] ToString () {
        return $this.name
    }
    static [IB_View] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/view"
        $bodyhashtable = @{name=$Name}
        If ($Comment){$bodyhashtable += @{comment=$Comment}}
        $Return = Invoke-RestMethod -uri $URIString -Method Post -body $bodyhashtable -WebSession $Session
        return [IB_View]::Get($gridmaster,$Session,$WapiVersion,$return)
    }
    static [IB_View] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ) {
        $ReturnFields = "extattrs,name,is_default,comment"
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $return = Invoke-RestMethod -Uri $URIString -WebSession $Session
        If ($Return) {
            return [IB_View]::New($Return.name, 
                                  $Return.is_default, 
                                  $Return.comment, 
                                  $Return._ref, 
                                  $($return.extattrs | ConvertTo-ExtAttrsArray))
        } else {
            return $Null
        }
                
    }


    static [IB_View[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Is_Default,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [Bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,name,is_default,comment"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/view?"
        If ($Strict){$Operator = ":="} else {$Operator = "~:="}
        If ($Name){
            $URI += "name$Operator$Name&"
        }
        If ($Is_Default){
            $URI += "is_default=$Is_Default&"
        }
        If ($comment){
            $URI += "comment$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringToIBQuery -searchstring $ExtAttribFilter
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -URI $URI -WebSession $Session
        [array]$output = Foreach ($item in $return){
                [IB_View]::New($item.name,
                                          $Item.is_default,
                                          $item.comment,
                                          $item._ref,
                                          $($item.extattrs | ConvertTo-ExtAttrsArray))
        }
        return $output
    }
#region Set Method
    hidden [void]Set (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyhashtable = $null
        $bodyhashtable += @{name=$Name}
        $bodyhashtable += @{comment=$Comment}
        If ($bodyhashtable){
            $return = Invoke-RestMethod -uri $URIString -method Put -body $($bodyhashtable | convertto-json) -contenttype application/json -WebSession $Session
            If ($return) {
                $this._ref = $return
                $this.name = $Name
                $this.comment = $Comment
            }
        }
    }
#constructors
    #These have to exist in order for the List method to create the object instance
    IB_View(
        [String]$name,
        [bool]$is_default,
        [string]$comment,
        [string]$_ref,
        [Object]$ExtAttrib
    ){
        $this.name       = $name
        $this.is_default = $is_default
        $this.Comment    = $comment
        $this._ref       = $_ref
        $this.extattrib  = $ExtAttrib
    }
}
Class IB_ZoneAuth : IB_ReferenceObject {
    ##Properties
    [String]$FQDN
    [String]$View
    [String]$ZoneFormat
    [String]$Comment
    [Object]$ExtAttrib
#region Create Method
    static [IB_ZoneAuth] Create(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$FQDN,
        [String]$View,
        [String]$ZoneFormat,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/zone_auth"
        $bodyhashtable = @{fqdn=$fqdn}
        If ($comment){$bodyhashtable += @{comment=$Comment}}
        If ($View){$bodyhashtable += @{view = $View}}
        If ($ZoneFormat){$bodyhashtable += @{zone_format = $zoneformat.ToUpper()}}
        $return = Invoke-RestMethod -uri $URIString -Method Post -Body $bodyhashtable -WebSession $Session
        return [IB_ZoneAuth]::Get($gridmaster,$Session,$WapiVersion,$return)
    }
#region Get Methods
    static [IB_ZoneAuth] Get (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$_ref
    ){
        $ReturnFields = "extattrs,fqdn,view,zone_format,comment"
        $URIstring = "https://$Gridmaster/wapi/$WapiVersion/$_ref`?_return_fields=$ReturnFields"
        $Return = Invoke-RestMethod -Uri $URIstring -WebSession $Session
        If ($Return){
            return [IB_ZoneAuth]::New($Return.FQDN,
                                         $return.view,
                                         $return.zone_format,
                                         $return.Comment,
                                         $($return.extattrs | convertto-ExtAttrsArray),
                                         $return._ref
            )
        } else {
            return $Null
        }
    }
    static [IB_ZoneAuth[]] Get(
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$FQDN,
        [String]$View,
        [String]$ZoneFormat,
        [String]$Comment,
        [String]$ExtAttribFilter,
        [bool]$Strict,
        [Int]$MaxResults
    ){
        $ReturnFields = "extattrs,fqdn,view,zone_format,comment"
        $URI = "https://$Gridmaster/wapi/$WapiVersion/zone_auth?"
        If ($Strict){$Operator = "="} else {$Operator = "~="}
        If ($FQDN){
            $URI += "fqdn$Operator$fqdn&"
        }
        If ($View){
            $URI += "view=$view&"
        }
        If ($ZoneFormat){
            $URI += "zone_format=$($ZoneFormat.ToUpper())&"
        }
        If ($comment){
            $URI += "comment`:$operator$comment&"
        }
        If ($ExtAttribFilter){
            $URI += SearchStringtoIBQuery -searchstring $ExtAttribFilter
        }
        If ($MaxResults){
            $URI += "_max_results=$MaxResults&"
        }
        $URI += "_return_fields=$ReturnFields"
        write-verbose "URI String: $URI"
        $return = Invoke-RestMethod -Uri $URI -WebSession $Session
        [array]$output = Foreach ($Item in $Return){
            [IB_ZoneAuth]::New($item.fqdn,
                                         $item.View,
                                         $item.zone_format,
                                         $item.Comment,
                                         $($item.extattrs | convertto-ExtAttrsArray),
                                         $item._ref
            )
        }
        return $Output
    }
#region Set Method
    hidden [void]Set (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Comment
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        $bodyhashtable = @{comment=$Comment}
        If ($bodyhashtable){
            $return = Invoke-RestMethod -uri $URIString -method Put -body $($bodyhashtable | convertto-json) -contenttype application/json -WebSession $Session
            If ($return) {
                $this._ref = $return
                $this.comment = $Comment
            }
        }
    }
#region AddExtAttrib method
    hidden [void] AddExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$Name,
        [String]$Value
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $Name -Value $(New-object psobject -Property @{value=$Value})
        $ExtAttr = new-object psobject -Property @{$Name=$(get-variable $Name | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs+"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_ZoneAuth]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
#region RemoveExtAttrib method
    hidden [void] RemoveExtAttrib (
        [String]$Gridmaster,
        [Object]$Session,
        [String]$WapiVersion,
        [String]$ExtAttrib
    ){
        $URIString = "https://$Gridmaster/wapi/$WapiVersion/$($this._ref)"
        New-Variable -name $ExtAttrib -Value $(New-object psobject -Property @{})
        $ExtAttr = new-object psobject -Property @{$extattrib=$(get-variable $ExtAttrib | Select-Object -ExpandProperty Value)}
        $body = new-object psobject -Property @{"extattrs-"=$extattr}
        $JSONBody = $body | ConvertTo-Json
        If ($JSONBody){
            $Return = Invoke-RestMethod -Uri $URIString -Method Put -Body $JSONBody -ContentType application/json -WebSession $Session
            If ($Return){
                $record = [IB_ZoneAuth]::Get($gridmaster,$Session,$WapiVersion,$return)
                $this.ExtAttrib = $record.extAttrib
            }
        }
    }
#region Constructors
    IB_ZoneAuth(
        [String]$fqdn,
        [String]$View,
        [String]$ZoneFormat,
        [String]$Comment,
        [object]$ExtAttrib,
        [String]$_ref
    ){
        $this.fqdn       = $fqdn
        $this.View       = $view
        $this.zoneformat = $zoneformat
        $this.Comment    = $Comment
        $this.ExtAttrib  = $ExtAttrib
        $this._ref       = $_ref
    }
}
Function Add-IBExtensibleAttribute {
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [object[]]$Record,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$EAName,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$EAValue,

        [Switch]$Passthru
    )
    BEGIN{        
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byRef'){
            Write-Verbose "$FunctionName`: Refstring passed, querying infoblox for record"
            $Record = Get-IBRecord -_Ref $_Ref
            If ($Record){
                 Write-Verbose "$FunctionName`: object found, passing to cmdlet through pipeline"
               $Record | Add-IBExtensibleAttribute -EAName $EAName -EAValue $EAValue -Passthru:$Passthru
            }
            
        } else {
            Foreach ($Item in $Record){
            # add code to validate ea data against extensible attribute definition on infoblox.
                If ($pscmdlet.ShouldProcess($Item)) {
                    write-verbose "$FunctionName`: Adding EA $eaname to $item"
                    $Item.AddExtAttrib($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$EAName,$EAValue)
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning dns object as output"
                        return $Item
                    }

                }
            }
        }
    }
    END{}
}
Function Find-IBRecord {
    [CmdletBinding(DefaultParameterSetName = 'globalSearchbyIP')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='globalSearchbyString')]
        [String]$SearchString,

        [Parameter(ParameterSetName='globalSearchbyString')]
        [String]$RecordType='*',

        [Parameter(ParameterSetName='globalSearchbyString')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='globalSearchbyIP')]
        [IPAddress]$IPAddress,

        [Int]$MaxResults

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
        get-ibview -Type dnsview | out-null
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        if ($pscmdlet.ParameterSetName -eq 'globalSearchbyString'){
            If ($Strict){
                $uribase = "https://$script:IBgridmaster/wapi/$Script:IBWapiVersion/search?search_string:="

            } else {
                $uribase = "https://$script:IBgridmaster/wapi/$Script:IBWapiVersion/search?search_string~:="

            }
        } elseif ($pscmdlet.ParameterSetName -eq 'globalSearchbyIP'){
            $uribase = "https://$script:IBgridmaster/wapi/$Script:IBWapiVersion/search?address="
        }
        
    }


    PROCESS{
        If ($SearchString){
            $URI = "$uribase$SearchString"
        } elseif ($IPAddress){
            $URI = "$uribase$($ipaddress.IPAddresstoString)"
        }
        If ($MaxResults){
            $Uri += "&_max_results=$MaxResults"
        }
        Write-verbose "$FunctionName`: URI String`: $uri"

        $output = Invoke-RestMethod -Uri $URI -WebSession $script:IBSession
        write-verbose "$FunctionName`: Found the following objects before filtering:"
        $output | ForEach-Object{write-verbose "`t`t$($_._ref)"}
        write-verbose "$FunctionName`: Found the following objects after filtering:"
        If ($output){
            foreach ($item in $output.where{$_._ref -like "$recordtype/*"}){
                write-verbose "`t`t$($item._ref)"
                Get-IBRecord -_ref $item._ref
            }
        }

    }
    END{}
}
Function Get-IBDNSARecord {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$Name,

        [Parameter(ParameterSetName='byQuery')]
        [IPAddress]$IPAddress,

        [Parameter(ParameterSetName='byQuery')]
        [String]$View,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Zone,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,

        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBgridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
            return
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for A Records"
            [IB_DNSARecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$IPAddress,$Comment,$ExtAttributeQuery,$Zone,$View,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for A record with reference string $_ref"
            [IB_DNSARecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBDNSCNameRecord {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$Name,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Canonical,

        [Parameter(ParameterSetName='byQuery')]
        [String]$View,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Zone,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,
        
        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for CName Records"
            [IB_DNSCNameRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$Canonical,$Comment,$ExtAttributeQuery,$Zone,$View,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for CName record with reference string $_ref"
            [IB_DNSCNameRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBDNSPTRRecord {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$Name,

        [Parameter(ParameterSetName='byQuery')]
        [IPAddress]$IPAddress,

        [Parameter(ParameterSetName='byQuery')]
        [String]$PTRDName,

        [Parameter(ParameterSetName='byQuery')]
        [String]$View,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Zone,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,
        
        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for PTR Records"
            [IB_DNSPTRRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$IPAddress,$PTRDName,$Comment,$ExtAttributeQuery,$Zone,$View,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for PTR record with reference string $_ref"
            [IB_DNSPTRRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBDNSZone {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$FQDN,
        
        [Parameter(ParameterSetName='byQuery')]
        [ValidateSet('Forward','ipv4','ipv6')]
        [String]$ZoneFormat,

        [Parameter(ParameterSetName='byQuery')]
        [String]$View,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,
        
        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for DNSZone Records"
            [IB_ZoneAuth]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$FQDN,$View,$ZoneFormat,$Comment,$ExtAttributeQuery,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for DNSZone record with reference string $_ref"
            [IB_ZoneAuth]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBExtensibleAttributeDefinition {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$Name,

        [Parameter(ParameterSetName='byQuery')]
        [ValidateSet('Date','Email','Enum','Integer','String','URL')]
        [String]$Type,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,

        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for extensible attribute definitions"
            [IB_extattrsdef]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$Type,$Comment,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for extensible attribute definitions with reference string $_ref"
            [IB_extattrsdef]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBFixedAddress {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [IPAddress]$IPAddress,

        [Parameter(ParameterSetName='byQuery')]
        [ValidatePattern('^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')]
        [String]$MAC,

        [Parameter(ParameterSetName='byQuery')]
        [String]$NetworkView,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,
        
        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type NetworkView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for FixedAddress Records"
            [IB_FixedAddress]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$IPAddress,$MAC,$Comment,$ExtAttributeQuery,$NetworkView,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for A record with reference string $_ref"
            [IB_FixedAddress]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBlease {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Name,
        
        [Parameter(ParameterSetName='byQuery')]
        [String]$IPAddress,

        [Parameter(ParameterSetName='byQuery')]
        [ValidatePattern('^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')]
        [String]$MAC,

        [Parameter(ParameterSetName='byQuery')]
        [String]$NetworkView,

        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type NetworkView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for DHCP Lease Records"
            [IB_Lease]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$IPAddress,$MAC,$NetworkView,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for DHCP lease with reference string $_ref"
            [IB_Lease]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBNetwork {
    [CmdletBinding(DefaultParameterSetName = 'byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [ValidateScript({If ($_ -match '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$') {
            $True
        } else {
            Throw "$_ is not a CIDR address"
        }})]
        [String]$Network,
        
        [Parameter(ParameterSetName='byQuery')]
        [ValidateScript({If ($_ -match '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$') {
            $True
        } else {
            Throw "$_ is not a CIDR address"
        }})]
        [String]$NetworkContainer,

        [Parameter(ParameterSetName='byQuery')]
        [String]$NetworkView,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,
        
        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byref')]
        [String]$_ref,

        [Int]$MaxResults
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type NetworkView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byQuery') {
            Write-Verbose "$FunctionName`: Performing query search for Network Records"
            [IB_Network]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Network,$NetworkView,$NetworkContainer,$Comment,$ExtAttributeQuery,$Strict,$MaxResults)
        } else {
            Write-Verbose "$FunctionName`: Querying $script:IBgridmaster for network record with reference string $_ref"
            [IB_Network]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        }
    }
    END{}
}
Function Get-IBRecord{
    [CmdletBinding(DefaultParameterSetName='byObject')]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True)]
        [ValidateNotNullorEmpty()]
        [String]$_Ref
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
        $return = Switch ($_ref.ToString().split('/')[0]) {
            'record:a' {[IB_DNSARecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'record:ptr' {[IB_DNSPTRRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'record:cname' {[IB_DNSCNameRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'fixedaddress' {[IB_FixedAddress]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'view' {[IB_View]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'networkview' {[IB_NetworkView]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            'extensibleattributedef' {[IB_ExtAttrsDef]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
            default {[IB_ReferenceObject]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)}
        }
        If ($Return){
            return $Return
        } else {
            return $Null
        }
    }
    END{}
}
Function Get-IBView {
    [CmdletBinding(DefaultParameterSetName='byQuery')]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(ParameterSetName='byQuery',Position=1)]
        [String]$Name,

        [Parameter(ParameterSetName='byQuery')]
        [String]$Comment,

        [Parameter(ParameterSetname='byQuery')]
        [String]$ExtAttributeQuery,
        
        [Parameter(ParameterSetName='byQuery')]
        [Switch]$Strict,

        [Parameter(ParameterSetName='byQuery')]
        [ValidateSet('True','False')]
        [String]$IsDefault,

        [Parameter(ParameterSetName='byQuery')]
        [int]$MaxResults,

        [Parameter(Mandatory=$True,ParameterSetName='byQuery')]
        [ValidateSet('DNSView','NetworkView')]
        [String]$Type,

        [Parameter(Mandatory=$True,ParameterSetName='byRef')]
        [String]$_Ref
    )
    $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
    write-verbose "$FunctionName`: Beginning Function"
    If (! $script:IBSession){
        write-verbose "Existing session to infoblox gridmaster does not exist."
        If ($gridmaster -and $Credential){
            write-verbose "Creating session to $gridmaster with user $($credential.username)"
            New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
        } else {
            write-error "Missing required parameters to connect to Gridmaster" -ea Stop
        }
    } else {
        write-verbose "Existing session to $script:IBGridmaster found"
    }
    Try {
        If ($pscmdlet.ParameterSetName -eq 'byRef'){
            Get-IBRecord -_ref $_Ref
        } else {
            If ($Type -eq 'DNSView'){
                Write-Verbose "$Functionname`: calling IB_View Get method with the following parameters`:"
                Write-Verbose "$FunctionName`: $name,$isDefault,$Comment,$Strict,$MaxResults"
                [IB_View]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$IsDefault,$Comment,$ExtAttributeQuery,$Strict,$MaxResults)
            } else {
                Write-Verbose "$Functionname`: calling IB_NetworkView Get method with the following parameters`:"
                Write-Verbose "$FunctionName`: $name,$isDefault,$Comment,$Strict,$MaxResults"
                [IB_NetworkView]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name,$IsDefault,$Comment,$ExtAttributeQuery,$Strict,$MaxResults)
            }

        }
    } Catch {
        Write-error "Unable to connect to Infoblox device $Script:IBgridmaster. Error code: $($_.exception)" -ea Stop
    }
}
Function New-IBDNSARecord {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$Name,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [IPAddress]$IPAddress,

        [String]$View,

        [String]$Comment,

        [uint32]$TTL = 4294967295

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBgridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($ttl -eq 4294967295){
            $use_ttl = $False
            $ttl = $Null
        } else {
            $use_TTL = $True
        }
        If ($pscmdlet.ShouldProcess($Name)){
            $output = [IB_DNSARecord]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $IPAddress, $Comment, $View, $ttl, $use_ttl)
            $output
        }
    }
    END{}
}
Function New-IBDNSCNameRecord {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$False)]
        [ValidateNotNullorEmpty()]
        [String]$Name,

        [Parameter(Mandatory=$False)]
        [ValidateNotNullorEmpty()]
        [String]$Canonical,

        [String]$View,

        [String]$Comment,

        [uint32]$TTL = 4294967295

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
             $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($ttl -eq 4294967295){
            $use_ttl = $False
            $ttl = $Null
        } else {
            $use_TTL = $True
        }
        If ($pscmdlet.ShouldProcess($Name)){
            $output = [IB_DNSCNameRecord]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $Canonical, $Comment, $View, $ttl, $use_ttl)
            $output
        }
    }
    
    END{}
}
Function New-IBDNSPTRRecord {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$PTRDName,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [IPAddress]$IPAddress,

        [String]$View,

        [String]$Comment,

        [UInt32]$TTL = 4294967295

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    #OverloadDefinitions
    #-------------------
    #static IB_DNSPTRRecord Create(string PTRDName, ipaddress IPAddress, string Comment, string view)

    PROCESS{
        If ($ttl -eq 4294967295){
            $use_ttl = $False
            $ttl = $Null
        } else {
            $use_TTL = $True
        }
        If ($pscmdlet.ShouldProcess($IPAddress)){
            $output = [IB_DNSPTRRecord]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$PTRDName, $IPAddress, $Comment, $View, $ttl, $use_ttl)
            $output
        }
    }
    END{}
}
Function New-IBDNSZone {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$FQDN,

        [ValidateSet('Forward','IPv4','IPv6')]
        [String]$ZoneFormat,

        [String]$View,

        [String]$Comment
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $gridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($pscmdlet.ShouldProcess($fqdn)){
            $output = [IB_ZoneAuth]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$FQDN, $View, $ZoneFormat, $Comment)
            $output
        }
    }
    END{}
}
Function New-IBExtensibleAttributeDefinition {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$Name,

        [Parameter(Mandatory=$True)]
        [ValidateSet('Date','Email','Enum','Integer','String','URL')]
        [String]$Type,

        [String]$DefaultValue,

        [String]$Comment

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($pscmdlet.ShouldProcess($Name)){
            $output = [IB_ExtAttrsDef]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $Type, $Comment, $DefaultValue)
            $output
        }
    }
    END{}
}
Function New-IBFixedAddress {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [IPAddress]$IPAddress,

        [ValidatePattern('^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')]
        [String]$MAC = '00:00:00:00:00:00',

        [String]$Name,

        [String]$NetworkView,

        [String]$Comment
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type NetworkView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($NetworkView){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $NetworkView){
                $NetworkViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $NetworkViewList" -ea Stop
            }
        }

    }

    PROCESS{
        If ($pscmdlet.ShouldProcess($IPAddress)){
            $output = [IB_FixedAddress]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $IPAddress, $Comment, $NetworkView, $MAC)
            $output
        }
    }
    END{}
}
Function New-IBNetwork {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateScript({If ($_ -match '^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$') {
            $True
        } else {
            Throw "$_ is not a CIDR address"
        }})]
        [String]$Network,

        [String]$NetworkView,

        [String]$Comment
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type NetworkView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($pscmdlet.ShouldProcess($Network)){
            $output = [IB_Network]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Network, $NetworkView, $Comment)
            $output
        }
    }
    END{}
}
Function New-IBView {
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$Name,
        
        [Parameter(Mandatory=$True)]
        [ValidateSet('DNSView','NetworkView')]
        [String]$Type,
        
        [String]$Comment
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
        Write-Verbose "$FunctionName`: Connecting to Infoblox device $script:IBgridmaster to retrieve Views"
        Try {
            $IBViews = Get-IBView -Type DNSView
        } Catch {
            Write-error "Unable to connect to Infoblox device $script:IBgridmaster. Error code: $($_.exception)" -ea Stop
        }
        If ($View){
            Write-Verbose "$FunctionName`: Validating View parameter against list from Infoblox device"
            If ($IBViews.name -cnotcontains $View){
                $ViewList = $ibviews.name -join ', '
                write-error "Invalid data for View parameter. Options are $ViewList" -ea Stop
            }
        }

    }
    PROCESS{
        If ($pscmdlet.ShouldProcess($Name)){
            If ($Type -eq 'DNSView'){
                $output = [IB_View]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $Comment)
                $output
            } else {
                $output = [IB_NetworkView]::Create($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $Comment)
                $output
            }
        }
    }
    END{}
}
Function New-IBWebSession {
    Param(
        [Parameter(Mandatory=$True)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [ValidateNotNullorEmpty()]
        [String]$Gridmaster,

        [Parameter(Mandatory=$True)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$False)]
        [String]$WapiVersion='v2.2'
    )
    $URI = "https://$gridmaster/wapi/$Wapiversion/grid"
    write-verbose "URIString: $URI"
    Invoke-RestMethod -uri $URI -Credential $Credential -SessionVariable Script:IBSession | out-null
    $script:IBGridmaster = $Gridmaster
    $script:IBWapiVersion = $WapiVersion
    new-object psobject -property @{
        'IBSession' = $script:IBSession
        'IBGridmaster' = $script:IBGridmaster
        'IBWapiVersion' = $script:IBWapiVersion
    }
}
Function Remove-IBDNSARecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSARecord[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_DNSARecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBDNSARecord
            }
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSRecord)) {
                    Write-Verbose "$FunctionName`: Deleting Record $DNSRecord"
                    $DNSRecord.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBDNSCNameRecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSCNameRecord[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_DNSCNameRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBDNSCNameRecord
            }
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSrecord)) {
                    Write-Verbose "$FunctionName`: Deleting Record $DNSRecord"
                    $DNSRecord.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBDNSPTRRecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSPTRRecord[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
                return
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){        
            $Record = [IB_DNSPTRRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBDNSPTRRecord
            }
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSrecord)) {
                    Write-Verbose "$FunctionName`: Deleting Record $DNSRecord"
                    $DNSRecord.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBDNSZone{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [ib_zoneauth[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [ib_zoneauth]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBDNSZone
            }
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    Write-Verbose "$FunctionName`: Deleting Record $Item"
                    $Item.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBExtensibleAttribute {
    [CmdletBinding(DefaultParameterSetName='byObjectEAName',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ParameterSetName='byRefEAName')]
        [Parameter(Mandatory=$False,ParameterSetName='byRefAll')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ParameterSetName='byRefEAName')]
        [Parameter(Mandatory=$False,ParameterSetName='byRefAll')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ParameterSetName='byRefEAName')]
        [Parameter(Mandatory=$True,ParameterSetName='byRefAll')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObjectEAName')]
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObjectAll')]
        [object[]]$Record,

        [Parameter(Mandatory=$True, ParameterSetName='byRefEAName')]
        [Parameter(Mandatory=$True, ParameterSetName='byObjectEAName')]
        [String]$EAName,

        [Parameter(Mandatory=$True, ParameterSetName='byRefAll')]
        [Parameter(Mandatory=$True, ParameterSetName='byObjectAll')]
        [Switch]$RemoveAll,

        [Switch]$Passthru
    )
    BEGIN{        
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        write-verbose "$FunctionName`: ParameterSetName=$($pscmdlet.ParameterSetName)"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq "byRefEAName"){
            Write-Verbose "$FunctionName`: Refstring passed, querying infoblox for record"
            $Record = Get-IBRecord -_Ref $_Ref
            If ($Record){
                Write-Verbose "$FunctionName`: object found, passing to cmdlet through pipeline"
                $Record | Remove-IBExtensibleAttribute -EAName $EAName -passthru:$Passthru
            }    
        } elseif($pscmdlet.ParameterSetName -eq "byRefAll"){
            Write-Verbose "$FunctionName`: Refstring passed, querying infoblox for record"
            $Record = Get-IBRecord -_Ref $_Ref
            If ($Record){
                Write-Verbose "$FunctionName`: object found, passing to cmdlet through pipeline"
                $Record | Remove-IBExtensibleAttribute -RemoveAll:$RemoveAll -passthru:$Passthru
            }    
        } else {
            Foreach ($Item in $Record){
                If ($RemoveAll){
                    write-verbose "$FunctionName`: Removeall switch specified, removing all extensible attributes from $item"
                    foreach ($EAName in $Item.extattrib.Name){
                        If ($pscmdlet.ShouldProcess($Item,"Remove EA $EAName")) {
                            write-verbose "$FunctionName`: Removing EA $EAName from $item"
                            $Item.RemoveExtAttrib($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$EAName)
                        }
                    }
                } else {
                    If ($pscmdlet.ShouldProcess($Item,"Remove EA $EAName")) {
                        write-verbose "$FunctionName`: Removing EA $EAName from $item"
                        $Item.RemoveExtAttrib($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$EAName)
                    }
                }
                If ($Passthru) {
                    Write-Verbose "$FunctionName`: Passthru specified, returning dns object as output"
                    return $Item
                }
            }
        }
    }
    END{}
}
Function Remove-IBExtensibleAttributeDefinition{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [IB_ExtAttrsDef[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_ExtAttrsDef]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBExtensibleAttributeDefinition
            }
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    Write-Verbose "$FunctionName`: Deleting Record $Item"
                    $Item.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBFixedAddress{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [IB_FixedAddress[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_FixedAddress]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBFixedAddress
            }
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    Write-Verbose "$FunctionName`: Deleting Record $Item"
                    $Item.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBLease{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [IB_Lease[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_Lease]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBLease
            }
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    Write-Verbose "$FunctionName`: Deleting Record $Item"
                    $Item.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBNetwork{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [IB_Network[]]$Record
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            $Record = [IB_Network]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Record){
                $Record | Remove-IBNetwork
            }
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    Write-Verbose "$FunctionName`: Deleting Record $Item"
                    $Item.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
                }
            }
        }
    }
    END{}
}
Function Remove-IBRecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True)]
        [ValidateNotNullorEmpty()]
        [String]$_Ref
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
        $Record = [IB_ReferenceObject]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
        If ($Record){
            Write-verbose "$FunctionName`: Record $_ref found, proceeding with deletion"
            If ($pscmdlet.ShouldProcess($Record)) {
                Write-Verbose "$FunctionName`: Deleting Record $Record"
                $Record.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
            }
        } else {
            Write-Verbose "$FunctionName`: No record found with reference string $_ref"
        }
    }
    END{}
}
Function Remove-IBView{
    [CmdletBinding(SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True)]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True)]
        [ValidateNotNullorEmpty()]
        [String]$_Ref

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
           If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
        Try {
            $object = [IB_View]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
        } Catch {
                write-verbose "No object of type IB_View found with reference string $_ref. Searching IB_NetworkView types"
        }
        If (! $object){
            Try {
                [IB_NetworkView]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_ref)
            }Catch{
                write-verbose "No object of type IB_NetworkView found with reference string $_ref"        
            }
        }
        If ($object){
            If ($pscmdlet.shouldProcess($object)){
                Write-Verbose "$FunctionName`: Deleting object $object"
                $object.Delete($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion)
            }
        } else {
            Write-error "No object found with reference string $_ref"
            return
        }
    }
    END{}
}
Function Set-IBDNSARecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSARecord[]]$Record,
        
        [IPAddress]$IPAddress,

        [String]$Comment,

        [uint32]$TTL,

        [Switch]$ClearTTL,

        [Switch]$Passthru

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
   }

    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            
            $Return = [IB_DNSARecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Return){
                $Params = $PSBoundParameters
                $Params.Add('Record',$Return)
                $Params.Remove('_Ref') | out-null
                If ($Params.keys -contains 'Gridmaster'){$Params.Remove('Gridmaster') | out-null}
                If ($Params.keys -contains 'Credential'){$Params.Remove('Credential') | out-null}
                Set-IBDNSARecord @Params
            }
            
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSRecord)) {
                    If ($PSBoundParameters.keys -contains "IPAddress"){
                        write-verbose "$FunctionName`: Setting IPAddress to $IPAddress"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$IPAddress, $DNSRecord.Comment, $DNSRecord.TTL, $DNSRecord.Use_TTL)
                    }
                    If ($PSBoundParameters.keys -contains "Comment"){
                        write-verbose "$FunctionName`: Setting comment to $comment"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSRecord.IPAddress, $Comment, $DNSRecord.TTL, $DNSRecord.Use_TTL)
                    }
                    If ($ClearTTL){
                        write-verbose "$FunctionName`: Setting TTL to 0 and Use_TTL to false"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSRecord.IPAddress, $DNSRecord.comment, $Null, $False)
                    } elseIf ($PSBoundParameters.keys -contains "TTL"){
                        write-verbose "$FunctionName`: Setting TTL to $TTL and Use_TTL to True"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSRecord.IPAddress, $DNSRecord.Comment, $TTL, $True)
                    }
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning dns object as output"
                        return $DNSRecord
                    }

                }
            }
        }
    }
    END{}
}
Function Set-IBDNSCNameRecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSCNameRecord[]]$Record,
        
        [String]$Canonical,

        [String]$Comment,

        [uint32]$TTL,

        [Switch]$ClearTTL,

        [Switch]$Passthru

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            
            $Return = [IB_DNSCNameRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Return){
                $Params = $PSBoundParameters
                $Params.Add('Record',$Return)
                $Params.Remove('_Ref') | Out-Null
                If ($Params.keys -contains 'Gridmaster'){$Params.Remove('Gridmaster') | out-null}
                If ($Params.keys -contains 'Credential'){$Params.Remove('Credential') | out-null}
                Set-IBDNSCNameRecord @Params
            }
            
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSrecord)) {
                    If ($PSBoundParameters.keys -contains 'Canonical'){
                        Write-Verbose "$FunctionName`: Setting canonical to $canonical"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$canonical, $DNSRecord.Comment, $DNSRecord.TTL, $DNSrecord.Use_TTL)
                    }
                    If ($PSBoundParameters.keys -contains 'comment'){
                        write-verbose "$FunctionName`: Setting comment to $comment"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSRecord.canonical, $Comment, $DNSRecord.TTL, $DNSRecord.Use_TTL)
                    }
                    If ($ClearTTL){
                        write-verbose "$FunctionName`: Setting TTL to 0 and Use_TTL to false"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSrecord.canonical, $DNSrecord.comment, $Null, $False)
                    } elseIf ($PSBoundParameters.keys -contains 'TTL'){
                        write-verbose "$FunctionName`: Setting TTL to $TTL and Use_TTL to True"
                        $DNSrecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSrecord.canonical, $DNSrecord.Comment, $TTL, $True)
                    }
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning dns object as output"
                        return $DNSRecord
                    }
                }
            }
        }
    }
    END{}
}
Function Set-IBDNSPTRRecord{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ValueFromPipeline=$True,ParameterSetName='byObject')]
        [IB_DNSPTRRecord[]]$Record,
        
        [String]$PTRDName,

        [String]$Comment,

        [uint32]$TTL,

        [Switch]$ClearTTL,

        [Switch]$Passthru

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            
            $Return = [IB_DNSPTRRecord]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Return){
                $Params = $PSBoundParameters
                $Params.Add('Record',$Return)
                $Params.Remove('_Ref') | out-null
                If ($Params.keys -contains 'Gridmaster'){$Params.Remove('Gridmaster') | out-null}
                If ($Params.keys -contains 'Credential'){$Params.Remove('Credential') | out-null}
                Set-IBDNSPTRRecord @Params
            }
            
        }else {
            Foreach ($DNSRecord in $Record){
                If ($pscmdlet.ShouldProcess($DNSrecord)) {
                    If ($PSBoundParameters.keys -contains 'PTRDName'){
                        Write-Verbose "$FunctionName`: Setting PTRDName to $PTRDName"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$PTRDName, $DNSRecord.Comment, $DNSRecord.TTL, $DNSrecord.Use_TTL)
                    }
                    If ($PSBoundParameters.keys -contains 'comment'){
                        write-verbose "$FunctionName`: Setting comment to $comment"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSRecord.PTRDName, $Comment, $DNSRecord.TTL, $DNSRecord.Use_TTL)
                    }
                    If ($ClearTTL){
                        write-verbose "$FunctionName`: Setting TTL to 0 and Use_TTL to false"
                        $DNSRecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSrecord.PTRDName, $DNSrecord.comment, $Null, $False)
                    } elseIf ($PSBoundParameters.keys -contains 'TTL'){
                        write-verbose "$FunctionName`: Setting TTL to $TTL and Use_TTL to True"
                        $DNSrecord.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$DNSrecord.PTRDName, $DNSrecord.Comment, $TTL, $True)
                    }
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning dns object as output"
                        return $DNSRecord
                    }
                }
            }
        }
    }
    END{}
}
Function Set-IBFixedAddress{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]
        [System.Management.Automation.Credential()]
        $Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,

        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [IB_FixedAddress[]]$Record,

        [String]$Name,

        [String]$Comment,
        
        [ValidatePattern('^([0-9A-Fa-f]{2}[:]){5}([0-9A-Fa-f]{2})$')]
        [String]$MAC,

        [Switch]$Passthru
    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
    }
    PROCESS{
            If ($pscmdlet.ParameterSetName -eq 'byRef'){
            
            $Return = [IB_FixedAddress]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            If ($Return){
                $Params = $PSBoundParameters
                $Params.Add('Record',$Return)
                $Params.Remove('_Ref') | out-null
                If ($Params.keys -contains 'Gridmaster'){$Params.Remove('Gridmaster') | out-null}
                If ($Params.keys -contains 'Credential'){$Params.Remove('Credential') | out-null}
                Set-IBFixedAddress @Params
            }
            
        }else {
            Foreach ($Item in $Record){
                If ($pscmdlet.ShouldProcess($Item)) {
                    If ($PSBoundParameters.keys -contains 'Name'){
                        write-verbose "$FunctionName`: Setting Name to $Name"
                        $Item.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $Item.Comment, $Item.MAC)
                    }
                    If ($PSBoundParameters.keys -contains 'comment'){
                        write-verbose "$FunctionName`: Setting comment to $comment"
                        $Item.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Item.Name, $Comment, $Item.MAC)
                    }
                    If ($PSBoundParameters.keys -contains 'MAC'){
                        write-verbose "$FunctionName`: Setting MAC to $MAC"
                        $Item.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Item.Name, $Item.Comment, $MAC)
                    }
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning object as output"
                        return $Item
                    }
                }
            }
        }
    }
    END{}
}
Function Set-IBView{
    [CmdletBinding(DefaultParameterSetName='byObject',SupportsShouldProcess=$True,ConfirmImpact="High")]
    Param(
        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateScript({If($_){Test-IBGridmaster $_ -quiet}})]
        [String]$Gridmaster,

        [Parameter(Mandatory=$False,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [System.Management.Automation.PSCredential]$Credential,

        [Parameter(Mandatory=$True,ValueFromPipelinebyPropertyName=$True,ParameterSetName='byRef')]
        [ValidateNotNullorEmpty()]
        [String]$_Ref,
        
        [Parameter(Mandatory=$True,ParameterSetName='byObject',ValueFromPipeline=$True)]
        [ValidateScript({$_.GetType().Name -eq 'IB_View' -or $_.GetType().name -eq 'IB_NetworkView'})]
        [object[]]$Record,
        
        [String]$Name,

        [String]$Comment,

        [Switch]$Passthru

    )
    BEGIN{
        $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
        write-verbose "$FunctionName`: Beginning Function"
        If (! $script:IBSession){
            write-verbose "Existing session to infoblox gridmaster does not exist."
            If ($gridmaster -and $Credential){
                write-verbose "Creating session to $gridmaster with user $($credential.username)"
                New-IBWebSession -gridmaster $Gridmaster -Credential $Credential -erroraction Stop  | out-null
            } else {
                write-error "Missing required parameters to connect to Gridmaster" -ea Stop
            }
        } else {
            write-verbose "Existing session to $script:IBGridmaster found"
        }
   }
    PROCESS{
        If ($pscmdlet.ParameterSetName -eq 'byRef'){
            If ($_Ref -like "view/*"){
                $Return = [IB_View]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            } elseif ($_Ref -like "networkview/*") {
                $Return = [IB_NetworkView]::Get($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$_Ref)
            }
            If ($Return){
                $Params = $PSBoundParameters
                $Params.Add('Record',$Return)
                $Params.Remove('_Ref') | Out-Null
                If ($Params.keys -contains 'Gridmaster'){$Params.Remove('Gridmaster') | out-null}
                If ($Params.keys -contains 'Credential'){$Params.Remove('Credential') | out-null}
                Set-IBView @Params
            }
        } else {
            foreach ($item in $Record){
                If ($pscmdlet.shouldProcess($item)){
                    If ($PSBoundParameters.keys -contains 'comment'){
                        write-verbose "$FunctionName`: Setting comment to $comment"
                        $item.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$item.Name, $Comment)
                    }
                    If ($PSBoundParameters.keys -contains 'Name'){
                        write-verbose "$FunctionName`: Setting name to $Name"
                        $item.Set($Script:IBGridmaster,$Script:IBSession,$Script:IBWapiVersion,$Name, $item.comment)
                    }
                    If ($Passthru) {
                        Write-Verbose "$FunctionName`: Passthru specified, returning object as output"
                        return $item
                    }
                }
            }
        }
    }
    END{}
}
Function Test-IBGridmaster {
    Param(
        [Parameter(Mandatory=$True)]
        [ValidateNotNullorEmpty()]
        [String]$Gridmaster,
        
        [Switch]$Quiet
    )
    $FunctionName = $pscmdlet.MyInvocation.InvocationName.ToUpper()
    write-verbose "$FunctionName`: Beginning Function"
        Try {
            write-verbose "$FunctionName`: Attempting connection to https://$gridmaster/wapidoc/"
            $data = invoke-webrequest -uri "https://$gridmaster/wapidoc/" -UseBasicParsing
            If ($Data){
                If ($Data.rawcontent -like "*Infoblox WAPI Documentation*"){
                    return $True
                } else {
                    If (! $Quiet){write-error "invalid data returned from $Gridmaster. Not a valid Infoblox device"}
                    return $False
                }
            } else {
                if (! $Quiet){write-error "No data returned from $gridmaster. Not a valid Infoblox device"}
                return $False
            }
        } Catch {
            if (! $Quiet){Write-error "Unable to connect to Infoblox device $gridmaster. Error code: $($_.exception)" -ea Stop}
            return $False
        }
}