powerbox icon indicating copy to clipboard operation
powerbox copied to clipboard

need help on the parameters

Open laboiteajb opened this issue 4 years ago • 7 comments

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

laboiteajb avatar Aug 20 '20 05:08 laboiteajb

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 avatar Aug 20 '20 06:08 BatmanAMA

about_Hash_Tables should help with anything more advanced.

BatmanAMA avatar Aug 20 '20 06:08 BatmanAMA

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

laboiteajb avatar Aug 20 '20 06:08 laboiteajb

@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

evilensky avatar Aug 20 '20 16:08 evilensky

@evilensky yes is it a copy paste error

laboiteajb avatar Aug 20 '20 22:08 laboiteajb

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?

laboiteajb avatar Aug 21 '20 04:08 laboiteajb

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.

BatmanAMA avatar Aug 21 '20 17:08 BatmanAMA