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

Clone-Object parameter handling (in powershell) differs from documentation #264

Open
terminatorbs opened this issue Jan 26, 2022 · 4 comments
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version

Comments

@terminatorbs
Copy link

Hi there

I am trying to add devices in bulk, and since Clone-Device lets me add them with pre-configured sensors that's what I'm going with. I am using Powershell with the provided .bat for this.

However, whenever I attempt to clone one, the new device does not have the expected specified properties, namely Device Name and Hostname. I'm attaching a screenshot of the issue, you can see in the returned device the properties do not match what's in the command. It appears it "skips" the Name part?

image

From reading the documentation, it appears to me that this is supposed to work, but in my case I had to add another parameter to make it work. Here a screenshot of the command producing the expected result:

image

Documentation I'm referring to: https://github.com/lordmilko/PrtgAPI/wiki/Object-Creation#cloning-1
Namely the following part:

# Clone the device with ID 1000 into the group or probe with ID 2001 naming the
# device "dc-2" and setting its hostname to "dc-2.contoso.local"
$newDevice = Get-Device -Id 1000 | Clone-Object -DestinationId 2001 "dc-2" "dc-2.contoso.local"

This is with the latest PrtgAPI downloaded today, against PRTG 21.3.70.1629, command run on a Windows Server 2019 build 17763

@terminatorbs terminatorbs changed the title Clone-Object parameter handling differs from documentation Clone-Object parameter handling (in powershell) differs from documentation Jan 26, 2022
@lordmilko lordmilko added the bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version label Jan 27, 2022
@lordmilko
Copy link
Owner

Hi @terminatorbs,

I've managed to successfully reproduce this issue

In the DeviceToDestination parameter set

  • the -DestinationId is positionally parameter 0,
  • -Name is parameter 1
  • and -Host is parameter 2

When parameter binding is happening however, the PowerShell engine appears to be assigning both parameters 0 and 1 to -Name (-Name is parameter 0 in the Manual parameter set).

Once it becomes apparent that the parameter set is not Manual and what would normally be parameter 0 (-DestinationId) was specified as a named parameter, you would expect the PowerShell engine would figure out that the the remaining parameters 0 and 1 now map to 1 and 2 (-Name and -Host), however that is clearly not what is happening.

I'll have to figure out how I can potentially modify this cmdlet so that this works as expected without breaking of the any other parameter sets on this cmdlet

@lordmilko
Copy link
Owner

Note that you can work around this issue for now by explicitly specifying the names of the parameters you're trying to use

Get-Device -Id 45503 | Clone-Object -DestinationId 45502 -Name "ACU02" -Host "10.100.47.20"

@terminatorbs
Copy link
Author

Thank you for the info! Yes, that's definitely a more solid solution than my workaround of adding a useless parameter, i'll adjust my script so it doesn't break when this is fixed.

Also, this might not be the place for it, but thank you so much for the work you put into this. I really appreciate the thorough documentation, and this project will save me tons of work.

@Silex
Copy link

Silex commented Jul 15, 2022

@lordmilko: seems there is still another bug:

PS C:\> Get-Module

Binary     0.9.17     PrtgApi                             {Add-Device, Add-Group, Add-NotificationTrigger, Add-Sensor...}                                            

PS C:\> Clone-Object -SourceId $template.Id -DestinationId $destination.Id -Name $ServerHostname -Host $ServerIp

Copy-Object : Parameter set cannot be resolved using the specified named parameters.

At line:1 char:1

+ Clone-Object -SourceId $template.Id -DestinationId $destination.Id -N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Copy-Object], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmbiguousParameterSet,PrtgAPI.PowerShell.Cmdlets.CloneObject

EDIT ok it works if I use the exact same form as you (piping the source).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues that have been confirmed to be bugs in PrtgAPI and will be fixed in a future version
Projects
None yet
Development

No branches or pull requests

3 participants