BatmanAMA / powerbox

Netbox powershell module
MIT License
48 stars 18 forks source link

need help on the parameters #39

Open laboiteajb opened 4 years ago

laboiteajb commented 4 years ago

Hello,

It's been a while since I touched the powershell, sorry for my level

I will want to create a script to add the switch configuration files to netbox.

is it possible to indicate several parameters to Get-nbInterface -query exemple : Get-nbInterface -query @{name='1/1'}, @{device = 'CR'}

thx

BatmanAMA commented 4 years ago

No problem! The structure for the query is a hash table, separate the pieces with a semi-colon.

Get-nbInterface -query @{name='1/1'; device = 'CR'}

BatmanAMA commented 4 years ago

about_Hash_Tables should help with anything more advanced.

laboiteajb commented 4 years ago

perfect thank you

I have another question (sorry)

I can't inject the result into a variable: $var = (Get-nbInterface -Query @ {name = '1/1'; device = 'CR'})

the variable contains the set of interfaces

evilensky commented 4 years ago

@laboiteajb That space between @ and { is invalid, is it a copy paste error or in your code?

> @ { key = 'value' }
ParserError:
Line |
   1 |  @ { key = 'value' }
     |  ~
     | Unrecognized token in source text.
> @{ key = 'value' }

Name                           Value
----                           -----
key                            value
laboiteajb commented 4 years ago

@evilensky yes is it a copy paste error

laboiteajb commented 4 years ago

I have good news, it works

$var = (Get-nbInterface -Query @{name = '1/1'; device = 'CR'})
Write-Host $var

if later I want to modify a value $var.name = "1/p" | Set-nbInterface

Here is the result

applet de commande Set-nbInterface à la position 1 du pipeline de la commande
Fournissez des valeurs pour les paramètres suivants :
object : 
PS C:\Users\jb> Get-nbObject
applet de commande Get-nbObject à la position 1 du pipeline de la commande
Fournissez des valeurs pour les paramètres suivants :
Resource : 

what is the object and the resources?

BatmanAMA commented 4 years ago

set-nbinterface isn't accepting pipeline input -

Set-NbInterface -Object $var

get-nbobject is a generic way of retrieving any object, you should use a specific get like Get-NBVirtualMachine instead. Get-NBVirtualMachine just wraps Get-NBObject -resource 'virtualization/virtual-machine' for example.