1 2 3 4 Previous Next 46 Replies Latest reply on Feb 20, 2020 10:55 AM by jvm2016 Go to original post
      • 30. Re: cannot bind parameter_powercli
        LucD Guru
        User ModeratorsCommunity WarriorsvExpert

        Are you getting any errors?

        Did you run it with Verbose on?

        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
        • 31. Re: cannot bind parameter_powercli
          jvm2016 Expert

          If you can run this function on lab and check it’s working for you.

          i Got all sort of errors intermittently and I don’t see any logic why it’s is failing when individual commands are working.

          • 32. Re: cannot bind parameter_powercli
            LucD Guru
            Community WarriorsUser ModeratorsvExpert

            There are a couple of issues with your function.

            Also, when doing an SSH to a VCSA, you first have to enter the 'shell' command, before you can actually use shell commands.
            That is why I use a shell stream.

             

            This is a version, including a call, that works for me.

             

            function create-contentlib {

                [cmdletbinding()]

                param (

                    [parameter(mandatory = $true,

                        valuefrompipeline = $true,

                        valuefrompipelinebypropertyname = $true)]

                    [string]$viserver,

                    [parameter(mandatory = $true)]

                    [PSCredential]$Credential_vcenter,

                    [parameter(mandatory = $true)]

                    [PSCredential]$Credential_root,

                    [parameter(mandatory = $true)]

                    [string]$datastore

                )


                Connect-VIServer -server $viserver -Credential $Credential_vcenter | Out-Null


                $session = New-SSHSession -ComputerName $viserver -Credential $Credential_root

                $stream = New-SSHShellStream -SSHSession $session -TerminalName xterm


                # Open shell

                Invoke-SSHStreamShellCommand -ShellStream $stream -PrompPattern "Shell access is granted" -Command 'shell' | Out-Null


                # Run command

                $result = Invoke-SSHStreamShellCommand -ShellStream $stream -PrompPattern "]#" -Command 'service-control --status vmware-content-library'


                if (($result -join '') -notmatch 'Running:') {

                    Write-Host "content lib service needs to be restarted " -ForegroundColor Blue

                    Invoke-SSHCommand -Command "service-control --start vmware-content-library" -SessionId $session_vcsa_id

                }


                Write-Host "creating content lib" -ForegroundColor Cyan

                $conlib = New-ContentLibrary -Name "siteA con lib" -Datastore (Get-Datastore -Name  $datastore) -Published -Description "content lib for site A vcenter"


                $stream.Close()

                Remove-SSHSession -SSHSession $session | Out-Null

            }

             

            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
            • 33. Re: cannot bind parameter_powercli
              jvm2016 Expert

              thanks luc ,

              i m going to check this on lab .

              • 34. Re: cannot bind parameter_powercli
                jvm2016 Expert

                Hi Luc ,

                 

                i am not sure why there is extra code which is not part of function .we are defining parameters for users in param block so its a again a duplication of those .

                logically function ends at Remove-SSHSession -SSHSession $session | Out-Null 

                and still its not working .

                 

                 

                # Update : code removed

                • 35. Re: cannot bind parameter_powercli
                  LucD Guru
                  vExpertCommunity WarriorsUser Moderators

                  Yes, that is other code that slipped in.
                  I removed it.

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 36. Re: cannot bind parameter_powercli
                    LucD Guru
                    Community WarriorsUser ModeratorsvExpert

                    And what is not working?

                    Worked ok for me.

                    Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                    • 37. Re: cannot bind parameter_powercli
                      jvm2016 Expert

                      but for me the function still not working .I mean the code which yu provided for function ..

                      • 38. Re: cannot bind parameter_powercli
                        LucD Guru
                        vExpertCommunity WarriorsUser Moderators

                        What is not working?
                        Error messages, verbose messages ...

                        Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                        • 39. Re: cannot bind parameter_powercli
                          jvm2016 Expert

                           

                          new-contentlibrary command is available

                           

                           

                          also there was sapce which i removed in get-datastore $datastore

                          • 40. Re: cannot bind parameter_powercli
                            jvm2016 Expert

                            all i am able to conclude is that get-contentlibrary comand which seems available from 11.5 vmware.vimautomation.core module is not working or not avaiable .

                            • 41. Re: cannot bind parameter_powercli
                              LucD Guru
                              Community WarriorsUser ModeratorsvExpert

                              Is this still in the HoL environment?

                              Which Lab?

                              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                              • 43. Re: cannot bind parameter_powercli
                                LucD Guru
                                Community WarriorsUser ModeratorsvExpert

                                Works for me

                                cl.jpg

                                But you have stop/start your PowerShell session after the Update-Module to 11.5

                                If I don't do that, I also get the same error.

                                Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                                • 44. Re: cannot bind parameter_powercli
                                  jvm2016 Expert

                                  i have been exposed to all sort of errors

                                   

                                  if yu could please check only this portion

                                   

                                   

                                   

                                  function create-contentlib {

                                      [cmdletbinding()]

                                   

                                   

                                      param (

                                   

                                   

                                          [parameter(mandatory = $true,

                                   

                                   

                                              valuefrompipeline = $true,

                                   

                                   

                                              valuefrompipelinebypropertyname = $true)]

                                   

                                   

                                          [string]$viserver,

                                   

                                   

                                          [parameter(mandatory = $true)]

                                   

                                   

                                          [PSCredential]$Credential_vcenter,

                                   

                                   

                                          [parameter(mandatory = $true)]

                                   

                                   

                                          [PSCredential]$Credential_root,

                                   

                                   

                                          [parameter(mandatory = $true)]

                                   

                                   

                                          [string]$datastore

                                   

                                   

                                      )

                                   

                                   

                                   

                                   

                                      Connect-VIServer -server $viserver -Credential $Credential_vcenter | Out-Null

                                   

                                   

                                   

                                   

                                      $session = New-SSHSession -ComputerName $viserver -Credential $Credential_root

                                   

                                   

                                      $stream = New-SSHShellStream -SSHSession $session -TerminalName xterm

                                   

                                   

                                   

                                   

                                      # Open shell

                                   

                                   

                                      Invoke-SSHStreamShellCommand -ShellStream $stream -PrompPattern "Shell access is granted" -Command 'shell' | Out-Null

                                   

                                   

                                   

                                   

                                      # Run command

                                   

                                   

                                      $result = Invoke-SSHStreamShellCommand -ShellStream $stream -PrompPattern "]#" -Command 'service-control --status vmware-content-library'

                                   

                                   

                                   

                                   

                                      if (($result -join '') -notmatch 'Running:') {

                                   

                                   

                                          Write-Host "content lib service needs to be restarted " -ForegroundColor Blue

                                   

                                   

                                          Invoke-SSHCommand -Command "service-control --start vmware-content-library" -SessionId $session_vcsa_id

                                   

                                   

                                      }

                                   

                                   

                                   

                                   

                                      Write-Host "creating content lib" -ForegroundColor Cyan

                                   

                                   

                                      $conlib = New-ContentLibrary -Name "siteA con lib" -Datastore (Get-Datastore -Name $datastore) -Published -Description "content lib for site A vcenter"

                                    

                                   

                                   

                                      $stream.Close()

                                   

                                   

                                      Remove-SSHSession -SSHSession $session | Out-Null

                                   

                                   

                                  }

                                   

                                  with following

                                  administrator@regiona.local

                                  VMware1! 

                                   

                                  root

                                  VMware1!

                                   

                                  datastore