VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

cannot bind parameter_powercli

hi luc ,

if yu could suggest how to fix this error  .this is one of the functions wherein it will create the content lib based on datasore provided .

[string]$datastore is one of the parameters   .do i need to change the string to something else ???

pastedImage_0.png

46 Replies
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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 ....

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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

of following   

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

I go to that library as well :smileygrin:


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you try with

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

yes .packages are dependent and can not be uninstalled .

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Then you just delete the folders, manually or programmatically.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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"

}

}

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Are you getting any errors?

Did you run it with Verbose on?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thanks luc ,

i m going to check this on lab .

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

And what is not working?

Worked ok for me.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

pastedImage_0.png

new-contentlibrary command is available

pastedImage_1.png

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

Reply
0 Kudos