CiscoDevNet / intersight-powershell

Cisco Intersight PowerShell
Apache License 2.0
16 stars 4 forks source link

New-IntersightBulkMoCloner attempt to clone bios policy fails #161

Closed aamodei closed 2 months ago

aamodei commented 3 months ago

Describe the bug Unable to use the "New-IntersightBulkMoCloner" cmdlet, it will either result in "Error calling CreateBulkMoCloner" with no further observable data OR Error calling CreateBulkMoCloner: {"Responses":[{"ObjectType":"bulk.RestResult","ClassId":"bulk.RestResult","Status":400,"Body":"{\"code\":\"InvalidRequest\",\"message\":\"Cannot execute the request. The JSON document is malformed.\" (when following example here - https://github.com/sandkum5/intersight-scripts/blob/main/powershell/clone-policies/cloneBiosPolicy.ps1)

To Reproduce (I have just included the snippet) the $existingpolicy.moid is an existing bios policy created by using the UI, $neworgobj is populated from Get-IntersightOrganizationOrganization.

Initialize Port Policy Source

    $PolicySrc = Initialize-IntersightMoBaseMo -ClassId "BiosPolicy" -ObjectType "BiosPolicy" -Moid $ExistingPolicy.Moid

    # Initialize Port Policy Target
    $PolicyTarget = Initialize-IntersightBiosPolicy -Name $NewPolicyName -Organization $NewOrgObj

    # Create Port Policy Clone
    New-IntersightBulkMoCloner -Sources $PolicySrc -Targets $PolicyTarget -Organization $NewOrgObj

Version used

Expected behavior Based on the example/explanation, a clone of the existing bios policy values under a new bios policy

Ghufz commented 3 months ago

It seems there is issue in passing $org variable to Organization parameter in target policy.

As a workaround if you are cloning the bios policy under same org then you may omit Organization parameter in target. as below

PolicyTarget = Initialize-IntersightBiosPolicy -Name $NewPolicyName

If you want to clone a policy into other organization then use Organization parameter in New-IntersightBulkMoCloner cmdlet as below

 # Initialize Port Policy Target
    $PolicyTarget = Initialize-IntersightBiosPolicy -Name $NewPolicyName 

    # Create Port Policy Clone
$Result =    New-IntersightBulkMoCloner -Sources $PolicySrc -Targets $PolicyTarget -Organization $NewOrgObj