yoke88 / PSPHPIPAM

MIT License
21 stars 18 forks source link
phpipam powershell

Powershell REST Client Module For PHPIPAM

Build status

this powershell module using PHPIPAM rest api to operate PHPIPAM tasks ,powershell version suggest 3.0 or above.

this module works on powershell core 6.0 and above now ,and the test environment is mainly on linux and powershell core

# if you just want to use it , install PSPHPIPAM module

Install-Module -Name PSPHPIPAM

# list command this module provide 

get-command -module PSPHPIPAM

# get help for a command

get-help Get-PhpIpamSubnet -full

# just get example of a command

get-help Get-PhpIpamSubnet -examples

# if you want to extend the module functions, read Docs\* and Tests\* under this project to gain idears.

Alerts

No support and test with PHPIPAM 'encryped' Application security mode.

用于PHPIPAM 的Powershell REST API 客户端

该powershell 模组使用PHPIPAM REST API来操作PHPIPAM的一些任务。建议powershell 3.0 或者更高版本,目前已经支持powershell core 6.0,最新的测试环境已经移到linux 环境,并且主要使用powershell core 6.x 进行测试.

该模块的主要结构和文件说明

- buildenv.* 可以用来创建PHPIPAM 开发测试环境,需要安装vagrant,virtualbox 参考 也可以直接使用docker-compose

Examples

Read the docs:

How to Debug

The functions in this module mainly used powershell advanced function feature (the function which contains [cmdletbinding()], so when you encounter errors ,you can add the -debug switch to see what's goging on there,you can add your write-debug expression to the function to see more information if you want.

Debug like this

New-PhpIpamSession -useCredAuth -PhpIpamApiUrl http://127.0.0.1/api -AppID script2 -userName admin -password password -debug

if you want to see raw network requests ,you can use below hacks to capture api request and response using a proxy

  1. for example you have a proxy listening at http://127.0.0.1:8088

    
    import-module PSPHPIPAM
    $module=Get-Module PSPHPIPAM
    # execute custom hack code in the module env
    # hack the default proxy value of invoke-restmethod command
    $module.Invoke({$PSDefaultParameterValues['invoke-restmethod:proxy']='http://127.0.0.1:8088'})
    # display $PSDefaultParameterValues in the module env
    $module.Invoke({$PSDefaultParameterValues})
    # test your code here
    Update-PhpIpamAddress -params @{id=279;description="test3";ip="127.0.0.254"}
    # the above code has not return and no error ,even using -debug param like below
    Update-PhpIpamAddress -params @{id=279;description="test3";ip="127.0.0.254"} -debug
    
    # but the log in proxy can see the detail 
    # {"code":400,"success":false,"message":"IP address cannot be changed","time":0.002}
    
    # we can see invoke-webrequest and invoke-restmethod will report simple 400 error and we can not see the error detail
    
    # the root cause of 400 return code is because. ip property is not use when patch address object 
    
    # the phpipam API doc will prove this