1 2 3 4 Previous Next 46 Replies Latest reply on Feb 20, 2020 10:55 AM by jvm2016 Go to original post
      • 15. Re: cannot bind parameter_powercli
        jvm2016 Expert

        oh you are right .just remember in order to have get-contentlibrary command available

        i just added import-module vmware.vimautomation.core -force

        • 16. Re: cannot bind parameter_powercli
          LucD Guru
          vExpertUser ModeratorsCommunity Warriors

          Does that mean that modules do not autoload in your setup?

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

            it does not even after setting autoloadingvariale to all as we discussed .

             

            can you please convert this function to incorporate try and catch and suggest that it can be use case of try and catch blocks?

            • 18. Re: cannot bind parameter_powercli
              LucD Guru
              User ModeratorsvExpertCommunity Warriors

              Can you attach the function as a file?
              I don't want to clean up the blank lines every time

               

              Btw, did you run the Get-Module before the New-ContentLibrary cmdlet?

              Also, does $env:PSModulePath contain the location where the PowerCLI modules are stored?

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

                1:i did following inside function but still function is unable to recognise new-contentlibray command

                 

                 

                 

                2:and as far as the path is concerned it will store in one of the three paths defined in $env:psmodulepath .do i need to alter anything here.

                • 20. Re: cannot bind parameter_powercli
                  LucD Guru
                  vExpertUser ModeratorsCommunity Warriors

                  No, the fact that you can load the module with Import-Module shows that PS can find the module.

                  Can you try adding the -Force switch on the Import-Module cmdlet?
                  And perhaps also the -Verbose switch to see what is going on.

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

                    I am going to check this again .i have tried force also earlier but it did not work .

                    it seems powershell or rather this function is getting confused   ♂️ and trying to get command from 11.0 or 11.2 where in content library commands are not available.

                    i was thinking to uninstall 11.0 and 11.2 ....

                    • 22. Re: cannot bind parameter_powercli
                      jvm2016 Expert

                      Also this has troubled me to an extent that I need to take help

                       

                      of following   

                      https://images.app.goo.gl/fFUVvrPE9uaGKzKu6

                      • 23. Re: cannot bind parameter_powercli
                        LucD Guru
                        User ModeratorsCommunity WarriorsvExpert

                        That is a good idea, try removing the pre-11.5 functions.

                         

                        I go to that library as well

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

                          i cant uninstall vmware.vimautomation.core 

                          i tried uninstalling the entire using get-module -name vmware* -listavailable|unistall-module

                           

                           

                          but in both cases i got package dependency .

                          any spefic command that resolves depenndency while uninstalling something like yum in linux.

                          • 25. Re: cannot bind parameter_powercli
                            LucD Guru
                            Community WarriorsvExpertUser Moderators

                            Did you try with

                             

                            Get-Module -Name VMware.PowerCLI -ListAvailable | Uninstall-Module

                            Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                            • 26. Re: cannot bind parameter_powercli
                              LucD Guru
                              vExpertUser ModeratorsCommunity Warriors

                              I spoke too soon.

                              This is a known issue in PowerShellGet, see #114

                               

                              Since it doesn't seem to have been fixed yet, it's back to the File Explorer or Remove-Item.

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

                                yes .packages are dependent and can not be uninstalled .

                                • 28. Re: cannot bind parameter_powercli
                                  LucD Guru
                                  User ModeratorsvExpertCommunity Warriors

                                  Then you just delete the folders, manually or programmatically.

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

                                    Hi Luc,

                                     

                                    if yu can check following function on lab .i dont see any issues when i run commands individually however not in function .

                                     

                                    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

                                     

                                     

                                     

                                     

                                    #checking content lib service using posh-ssh

                                    #$cred_root=Get-Credential

                                    $session_vcsa=New-SSHSession -ComputerName vcsa-01a.corp.local -Credential $cred_root

                                    $session_vcsa_id=$session_vcsa.SessionId

                                     

                                     

                                    $conlib=Invoke-SSHCommand -Command "service-control --status vmware-content-library" -SessionId $session_vcsa_id

                                    if ($conlib.output -icontains "running:")

                                     

                                     

                                     

                                     

                                    {

                                     

                                     

                                     

                                     

                                    write-host "service of content lib is running "

                                    write-host "creating content lib" -ForegroundColor Cyan

                                     

                                     

                                     

                                     

                                    #Connect-VIServer -server vcsa-01a.corp.local -Credential $Credential_vcenter

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

                                     

                                     

                                    #publishing to secondary site

                                     

                                     

                                    #$conlib.PublishUrl

                                    #New-ContentLibrary -Name "subscribed to siteB" -SubscriptionUrl $conlib.PublishUrl -Description "subscribed to site B" -datastore (get-datastore) -AutomaticSync

                                     

                                     

                                     

                                     

                                    }

                                     

                                     

                                    else

                                    {

                                     

                                     

                                    write-host "content lib service needs to be restarted " -ForegroundColor Blue

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

                                    Connect-VIServer -server vcsa-01a.corp.local -Credential $cred_administrator

                                    write-host "creating content lib" -ForegroundColor Cyan

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

                                     

                                     

                                     

                                     

                                    }

                                     

                                     

                                    }