PowerCLI

 View Only
  • 1.  Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 06, 2020 07:07 PM

    My Environment is Window10 with PowerShell 5.1 and PowerCLI 12.0

    VCSA is 6.7.0 - 16709110

    Hypervisor: VMware ESXi, 6.7.0, 16713306

    I started by have some real issues with the GET-VM and GET-VAPP when I specified the "-Location" parameter

    so I would consistently get an Exception on the command:

    $VMs = GET-VM -Location Agent.Carter

    Yields:

    PS H:\> get-vm -location Agent.Carter

    get-vm : 10/6/2020 2:00:42 PM    Get-VM        Value cannot be null.

    Parameter name: collection   

    At line:1 char:1

    + get-vm -location Agent.Carter

    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [Get-VM], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

    Where the <Agent.Carter> is a folder on the vCenter where all the users vApps are stored.

    I found that if I replaced that command with:

    $VMs = Get-Folder Agent.Carter | GET-VM

    it would accomplish the task at hand, give me a list of VMs for a user BUT then this Exception became apparent.

    My Snippet of script looks like:

    write-host "    Starting Cloning of '$vApp' to '$NewName' on '$Datastore' $($FreeSpace)GB Available ... " -noNewLine

    # Run command and capture output

    $Cluster = Get-Cluster $Cluster_Name 2>&1

    $Results = New-vapp -Name $NewName -vapp (get-vapp -name $vApp.name) -location $Cluster -Datastore $Datastore 2>&1

    write-host "Complete`n    Moving new vApp to folder $Location ... " -noNewLine

    write-host "`$Location is $($Location.gettype())"

    move-vapp  -vapp $NewName -Destination $Location | Out-Null

    write-host "Complete"

    The results (Error Message) is what follows:

        Starting Cloning of '_Mod3_Class' to '20550_Agent.Carter-Mod3_Class' on 'JCAC_Datastore_1' 2142GB Available ... Complete

        Moving new vApp to folder Agent.Carter ... $Location is VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl

    move-vapp : 10/6/2020 11:11:06 AM    Move-VApp        Value cannot be null.

    Parameter name: collection   

    At C:\Users\Mike\Desktop\VM-Builder1.90.ps1:1645 char:5

    +     move-vapp  -vapp $NewName -Destination $Location | Out-Null

    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [Move-VApp], VimException

        + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.MoveVApp

    The Cloning is working but when I try to move the VAPP to the users folder I get that same NULL Exception.  I figure at this point what I am experiencing is some code issue in the .Net Frame code that is being called by the PowerShell CMDLETs.



  • 2.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 06, 2020 07:18 PM

    What do you have in $Location, a string, or a Folder object returned by Get-Folder?


    The same question for the VApp parameter, did you already try with the VApp object (you have it in $Results)?



  • 3.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 02:15 PM

    the $location is populated from a Get-Folder call so it is of type VMware.VimAutomation.ViCore.Impl.V1.Inventory.FolderImpl

    The $vApp is an object that I created to hold app info, so I do a call to (get-vapp -name $vApp.name) to supply an actual vApp value.

    I have tried to go through and remove all Parameters that specify a location value and so most of my script is working well, but when I have no choice with using the -Location parameter or a similar parameter it will sometimes fail.

    I have another little snippet (now that my session has hit the limit or whatever the issue is:

    try {

        # $results = Get-VApp $vAppName | Get-VIPermission  -Principal $stu.GetPrincipal()

        $results = get-vapp -location michael.P

    } catch [System.ArgumentNullException] {

        Write-Host "NULL Exception Raised. Close the session and run the script again." -ForegroundColor Yellow

        Write-Host "StackTrace:`n$($_.ScriptStackTrace)" -ForegroundColor Red

        Write-Host "Exception:`n$($_.Exception)" -ForegroundColor Red

        Write-Host "Error Details:`n$($_.ErrorDetails)" -ForegroundColor Red

    }

    In the script above, there is a folder on the VCSA named "Michael.P" and below is the output of the script. (line 6 is the one command in the TRY section of the scriptblock.

    NULL Exception Raised. Close the session and run the script again.

    StackTrace:

    at <ScriptBlock>, <No file>: line 6

    Exception:

    VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 10/8/2020 8:56:01 AM    Get-VApp        Value cannot be null.

    Parameter name: collection     ---> System.ArgumentNullException: Value cannot be null.

    Parameter name: collection

       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)

       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)

       at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)

       at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList)

       at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.GetObjectsByNameCore(PropertyInfo parameter, String objectName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByNameCore(PropertyInfo parameter, String objectName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByName(PropertyInfo parameter)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectsByName()

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.SelectObjectsByName()

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

       at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

       --- End of inner exception stack trace ---

       at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

    Error Details:

    I thought I had gotten Error Details before, but nothing was shown this time.

    Please let me know if you more questions or suggestions.



  • 4.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 02:19 PM

    I'm afraid you didn't get my remark.

    Instead of using a string on the Location parameter, use the object returned by Get-VApp or New-VApp.

    $results = get-vapp -location (Get-Folder -Name michael.P)



  • 5.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 02:37 PM

    It worked when I changed the call to get-vApp as you suggested, Now my other command to get-vipermissions still throws the exception

    The results of the "$stu.GetPrincipal()" is a string with my account information in it.

    -=-=-=-=-=-=-==- Script:-=-=-=-=-=-=-=-=-

    $vappName = "P,Michael-Mod6_Class"

    $Principal = "outdomain\michael.p"

    try {

        $results = Get-VApp $vAppName | Get-VIPermission  -Principal $Principal

        # $results = get-vapp -location (get-folder -name michael.p)

    } catch [System.ArgumentNullException] {

        Write-Host "NULL Exception Raised. Close the session and run the script again." -ForegroundColor Yellow

        Write-Host "StackTrace:`n$($_.ScriptStackTrace)" -ForegroundColor Red

        Write-Host "Exception:`n$($_.Exception)" -ForegroundColor Red

        Write-Host "Error Details:`n$($_.ErrorDetails)" -ForegroundColor Red

    } catch  {

        Write-Host "An Error occurred trying to look at Permissions - May have to close Session and re-run script"

        Write-Host "$_" -ForegroundColor Red

        Write-Host "StackTrace:`n$($_.ScriptStackTrace)" -ForegroundColor Red

        Write-Host "Exception:`n$($_.Exception)" -ForegroundColor Red

        Write-Host "Error Details:`n$($_.ErrorDetails)" -ForegroundColor Red

    }

    Write-host "Results of TRY Command: "

    $results | ft -AutoSize

    -=-=-=-=-=-=-=-=-=-= Output -=-=-=-=-=-=-=-=-=

    NULL Exception Raised. Close the session and run the script again.

    StackTrace:

    at <ScriptBlock>, <No file>: line 4

    Exception:

    VMware.VimAutomation.Sdk.Types.V1.ErrorHandling.VimException.VimException: 10/8/2020 9:33:23 AM    Get-VIPermission        Value cannot be null.

    Parameter name: collection     ---> System.ArgumentNullException: Value cannot be null.

    Parameter name: collection

       at System.ThrowHelper.ThrowArgumentNullException(ExceptionArgument argument)

       at System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection)

       at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)

       at VMware.VimAutomation.WorkloadManagement.Impl.V1.WMObnProvider.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList)

       at VMware.VimAutomation.Sdk.Impl.V1.CoreServiceImpl.GetObn(IList`1 connectionIdList, IList`1 objectNameList, IList`1 objectInterfaceTypeList, IList`1 contextList, String contextRelationName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.GetObjectsByNameCore(PropertyInfo parameter, String objectName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByNameCore(PropertyInfo parameter, String objectName)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectByName(PropertyInfo parameter)

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.ObnSelector.SelectObjectsByName()

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.SelectObjectsByName()

       at VMware.VimAutomation.Sdk.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

       at VMware.VimAutomation.ViCore.Util10Ps.BaseCmdlet.BaseCmdlet.ProcessRecordErrorHandled()

       --- End of inner exception stack trace ---

       at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)

    Error Details:

    Results of TRY Command:



  • 6.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 02:48 PM

    Did you also try with this notation?
    You probably have to complete the domainname, since the NetBIOS name is usually shorter

    $Principal = "michael.p@outdomain..."



  • 7.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 03:01 PM

    Sorry, I changed the real value which is dotted domain name to a short name.

    the value I use in the call is the exact text as shown when I do a simple Get-VIPermission on a vApp

    The String value looks a lot like "xxxxx.xxxxx\michael.p" as shown in the output below: (Again, editing some of the specifics)

    PS H:\> Get-VApp -name $vAppName |  Get-VIPermission | ft -au                                                                          
    Role                     Principal                                                             PropagateisGroup
    ----                     ---------                                                             ----------------
    XXXX_PRIV_USER           VSPHERE.YYYY.LOCAL\ed.k                                         True  False
    XXXX_USER_INSTRUCTOR     YYYY.WWWW\DL_C_XXXX_Instructors                                   True  True
    XXXX_PRIV_USER           YYYY.WWWW\DL_C_XXXX_VM_Privileged_Users                           True  True
    XXXX_USER_INSTRUCTOR     YYYY.WWWW\DL_C_XXXX_SME                                           True  True
    Admin                    VSPHERE.YYYY.LOCAL\vpxd-c0abd9a4-5b40-41c1-b78a-c7b15e77499b          True  False
    vSphere Client Solution User VSPHERE.YYYY.LOCAL\vsphere-webclient-c0abd9a4-5b40-41c1-b78a-c7b15e77499b True  False
    Admin                    VSPHERE.YYYY.LOCAL\vpxd-extension-c0abd9a4-5b40-41c1-b78a-c7b15e77499bTrue  False
    Admin                    VSPHERE.YYYY.LOCAL\Administrator                                      True  False
    Admin                    YYYY.WWWW\DL_YYYY_Virtual_Admin                                       True  True
    AutoUpdateUser           VSPHERE.YYYY.LOCAL\AutoUpdate                                         True  True
    Admin                    VSPHERE.YYYY.LOCAL\Administrators                                     True  True


  • 8.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 03:28 PM

    Ok, so it is all working now?



  • 9.  RE: Value cannot be NULL with GET-VM and GET-VAPP

    Posted Oct 08, 2020 02:50 PM

    well, I found a way around the issue of passing in the "-Principal [String]"

    I changed the command to:

    $results = Get-VApp -name $vAppName | Get-VIPermission | where Principal -eq $Principal

    This seems to work