Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a new Subnet #12

Open
andrewchown opened this issue Apr 12, 2019 · 8 comments
Open

Adding a new Subnet #12

andrewchown opened this issue Apr 12, 2019 · 8 comments

Comments

@andrewchown
Copy link

Hi there i'm trying to add a new subnet but getting an error. I used Get-PhpIpamSubnetByID to copy the object but no luck. Any help would be great:

Create the new object:

$newsubnet =@()
$object = New-Object –TypeName PSObject
$object | Add-Member –MemberType NoteProperty –Name subnet –Value '10.10.10.0'
$object | Add-Member –MemberType NoteProperty –Name mask –Value '24'
$object | Add-Member –MemberType NoteProperty –Name description –Value 'bbbb'
$object | Add-Member –MemberType NoteProperty –Name sectionId –Value '1'
#$object | Add-Member –MemberType NoteProperty –Name linked_subnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name vlanId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name vrfId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name masterSubnetId –Value '170'
$object | Add-Member –MemberType NoteProperty –Name nameserverId –Value '0'
$object | Add-Member –MemberType NoteProperty –Name showName –Value '0'
#$object | Add-Member –MemberType NoteProperty –Name permissions –Value
$object | Add-Member –MemberType NoteProperty –Name DNSrecursive –Value '0'
$object | Add-Member –MemberType NoteProperty –Name DNSrecords –Value '0'
$object | Add-Member –MemberType NoteProperty –Name allowRequests –Value '0'
$object | Add-Member –MemberType NoteProperty –Name scanAgent –Value '0'
$object | Add-Member –MemberType NoteProperty –Name pingSubnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name discoverSubnet –Value '0'
$object | Add-Member –MemberType NoteProperty –Name isFolder –Value '0'
$object | Add-Member –MemberType NoteProperty –Name isFull –Value '0'
$object | Add-Member –MemberType NoteProperty –Name state –Value '0'
$object | Add-Member –MemberType NoteProperty –Name threshold –Value '0'
#$object | Add-Member –MemberType NoteProperty –Name firewallAddressObject –Value '0'
$object | Add-Member –MemberType NoteProperty –Name location –Value '4'
$object | Add-Member –MemberType NoteProperty –Name device –Value '0'
$object | Add-Member –MemberType NoteProperty –Name tag –Value '0'
$object | Add-Member –MemberType NoteProperty –Name resolveDNS –Value '0'
$newsubnet += $object

Try to use the object:
New-PhpIpamSubnet -Params $newsubnet

Error:

image

New-PhpIpamSubnet : Cannot validate argument on parameter 'Params'. The "$_ -is [system.collections.hashtable]" validation script for the argument with value "@{subnet=10.10.10.0; mask=24;
description=bbbb; sectionId=1; vlanId=0; vrfId=0; masterSubnetId=170; nameserverId=0; showName=0; DNSrecursive=0; DNSrecords=0; allowRequests=0; scanAgent=0; pingSubnet=0; discoverSubnet=0;
isFolder=0; isFull=0; state=0; threshold=0; location=4; device=0; tag=0; resolveDNS=0}" did not return a result of True. Determine why the validation script failed, and then try the command
again.
At line:1 char:27

  • New-PhpIpamSubnet -Params $newsubnet
  •                       ~~~~~~~~~~
    
    • CategoryInfo : InvalidData: (:) [New-PhpIpamSubnet], ParameterBindingValidationException
    • FullyQualifiedErrorId : ParameterArgumentValidationError,New-PhpIpamSubnet
@yoke88
Copy link
Owner

yoke88 commented Apr 12, 2019 via email

@andrewchown
Copy link
Author

Hi, thanks for the reply. Still getting an error:

Command:
new-PhpIpamSubnet -params @{subnet='10.10.10.0';mask='24';description='test';sectionId='1';vlanId='0';vrfId='0';masterSubnetId='170';nameserverId='0';showName='0';DNSrecursive='0';DNSrecords='0';allowRequests='0';scanAgent='0';pingSubnet='0';discoverSubnet='0';isFolder='0';isFull='0';threshold='0';location='0';device='0';tag='0';resolveDNS='0'}

image

Invoke-PhpIpamExecute : {"code":400,"success":0,"message":"Request is not valid","time":0.001}
At C:\TMP\PSPHPIPAM\Functions\Subnets.ps1:191 char:14

  • ... if($(Invoke-PhpIpamExecute -method post -controller subnets -p ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    • FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-PhpIpamExecute

@yoke88
Copy link
Owner

yoke88 commented Apr 13, 2019 via email

@yoke88
Copy link
Owner

yoke88 commented Apr 13, 2019

and there are two functions to aid you work with get-* object and reuse it to create a new object or update a object.

connvertTo-HashtableFromPsCustomObject
ConvertTo-PsCustomObjectFromHashtable

you must reference the api doc, to confirm which param can be used and the param type.

common mistakes are post wrong or unnecessary param or the param type is wrong

and you can reference #5

@andrewchown
Copy link
Author

Hi thanks again for the help. I've tried the below command and many variations on it but still no luck.

new-PhpIpamSubnet -params @{masterSubnetId=170;description="test";subnet="10.10.10.0";mask=24;sectionId=1;location=4}

Do you have a way to find out which properties are mandatory? Do you have an example of a subnet POST command you have working? I can't see a log in PHPIPAM to try and fault find this.

@yoke88
Copy link
Owner

yoke88 commented Apr 16, 2019

only sectionid is mandatory,you must read the api doc. if you have trouble add -debug switch for the command you execute.

for example

new-PhpIpamSubnet -params @{masterSubnetId=170;description="test";subnet="10.10.10.0";mask=24;sectionId=1;location=4} -debug

@andrewchown
Copy link
Author

andrewchown commented Jun 14, 2019 via email

@yoke88
Copy link
Owner

yoke88 commented Jun 16, 2019

New-PhpIpamSubnet -Params @{sectionId=1;subnet='192.168.10.0';mask=24}

PS /> $subnet=Get-PhpIpamAllSubnets|?{$_.subnet -eq '192.168.10.0' -and $_.sectionid -eq 1 }
PS /> $subnet

id                    : 8
subnet                : 192.168.10.0
mask                  : 24
sectionId             : 1
description           : 
linked_subnet         : 
firewallAddressObject : 
vrfId                 : 
masterSubnetId        : 0
allowRequests         : 0
vlanId                : 
showName              : 0
device                : 0
permissions           : {"3":"1","2":"2"}
pingSubnet            : 0
discoverSubnet        : 0
resolveDNS            : 0
DNSrecursive          : 0
DNSrecords            : 0
nameserverId          : 0
scanAgent             : 
isFolder              : 0
isFull                : 0
tag                   : 2
threshold             : 0
location              : 
editDate              : 
lastScan              : 
lastDiscovery         : 
usage                 : @{used=0; maxhosts=254; freehosts=254; freehosts_percent=100; Offline_percent=0; Used_percent=0; 
                        Reserved_percent=0; DHCP_percent=0}

PS /> $UpdatedSubnet=@{id=$subnet.id;description="this was a test"}
PS /> Update-PhpIpamSubnet -Params $UpdatedSubnet
True
PS /> Remove-PhpIpamSubnetByID -ID $subnet.id 
True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants