Closed Soeren-FT closed 4 years ago
Hi there! What is in your $dhcpSite and $tenant urls? It should be a string that matches the slug attribute of the tenant/site you are looking for.
You should be able to test this functionality using ConvertTo-nbId -Source 'dcim/sites' -value 'my-site-slug'
Thanks!
Hey,
thanks for you reply. Yes, it works with the slug attribute. I'm just wondering, why my script works well if i use a simple string for find the right tenant. Now it works well in the dynamicly way: {$dhcpSite = (Get-nbSite | where{$_.name -like 'xxxxxxx'}).slug}
$tenant = (Get-nbTenant | where {$.name -like (Get-nbsite | Where-Object {$.slug -eq "$dhcpSite"}).tenant}).slug
Tahnk you!
I'm saying specifically, all the -lookup argument does is convert slug to ID for the set operation. This is an aspect of the functions I built in in the background to make it so that users can get-nbobject, then manipulate the properties, then set-nbobject. I exposed it instead of hiding it because it might open up the module for things users want to do to avoid having to do lookups themselves. In the future, it might be better to do this work in a set of classes for netbox, but I tried to do this in a classless way because I didn't want to hand code a big set of classes or fix one of the many swagger->ps1 libraries out there to work with this API. I'm glad you've figured your issue out :)
The lookup parameter in New-nbPrefix and New-nbObject -Resource 'ipam/prefixes' is not working. There is no error message if a lookup variable is define and lookup parameter are declined in $object, :
$dhcpPrefix = [pscustomobject]@{ prefix = $nbScope family = 'IPv4' site = $dhcpSite tenant = $tenant } $nbLookup = @{ site = 'dcim/sites' tenant = 'tenancy/tenants' }
id : 128 family : @{value=4; label=IPv4} prefix : x.x.x.x/xx site : vrf : tenant : vlan : status : @{value=active; label=Active; id=1} role : is_pool : False description : tags : {} custom_fields : created : 2020-02-10 last_updated : 2020-02-10T15:20:33.768035+01:00
but if there is no look up variable of the needed paramerter the right error occured: Invoke-nbApi : {"site":["Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value: xxx"],"tenant":["Related objects must be referenced by numeric ID or by dictionary of attributes. Received an unrecognized value: xxx"]}