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

need help on the parameters #39

Open
laboiteajb opened this issue Aug 20, 2020 · 7 comments
Open

need help on the parameters #39

laboiteajb opened this issue Aug 20, 2020 · 7 comments

Comments

@laboiteajb
Copy link

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
Copy link
Owner

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
Copy link
Owner

about_Hash_Tables should help with anything more advanced.

@laboiteajb
Copy link
Author

laboiteajb commented Aug 20, 2020

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
Copy link

@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
Copy link
Author

@evilensky yes is it a copy paste error

@laboiteajb
Copy link
Author

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
Copy link
Owner

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.

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

3 participants