Highlighted
Hot Shot
Hot Shot

cannot bind parameter_powercli

Jump to solution

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

1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

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

View solution in original post

0 Kudos
46 Replies
Highlighted
User Moderator
User Moderator

The New-ContentLibrary cmdlet doesn't seem to support OBN for the Datastore parameter.
You will have to do a Get-Datastore to pass the parameter.

New-ContentLibrary -Name Test -Datastore (Get-Datastore -Name TestDS)


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

it was working fine yesterday .today its not :smileyplain:

0 Kudos
Highlighted
User Moderator
User Moderator

Did you change PowerCLI versions in between?


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

well content library commands are available from 11.5 version onwards and thats why i updated powercli .

however if you see below example it is actually taking value from variable

pastedImage_0.png

0 Kudos
Highlighted
User Moderator
User Moderator

Correct, but that variable most probably contains a Datastore object, not a String.

I repeat, it looks as if the PowerCLI Dev Team didn't use OBN on the Datastore parameter of the cmdlet


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

i am going to check this again .

0 Kudos
Highlighted
Expert
Expert

I notice your screenshot example is calling a `create-contentlibrary` rather than the official cmdlet `New-ContentLibrary`.  Are you using a custom module/function?  That would probably explain the difference in behavior.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
0 Kudos
Highlighted
User Moderator
User Moderator

The user is creating a module.
The Create-ContentLibrary is his function, in there he calls New-ContentLibrary.


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

Highlighted
Hot Shot
Hot Shot

new-contentlibrary is a strightforward powercli comand .

however in this thread we are using that command under function  create-contentlibray which has included concept of

checking service using posh-ssh module and at the same time publishing to secondary site if any .

0 Kudos
Highlighted
Hot Shot
Hot Shot

i see a different weired issue the comand new-contentlibrary is avaliable but i cant use inside function.

pastedImage_0.png

0 Kudos
Highlighted
User Moderator
User Moderator

I would need to see the code to analyse.
I suspect that there might be a quote issue somewhere


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

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"

}

}

above is what i am trying .it assumes that posh-ssh is already installed.

0 Kudos
Highlighted
User Moderator
User Moderator

That code doesn't have a problem as far as I can see.

But then this is probably not the code you ran since the line number in the error doesn't correspond.


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

0 Kudos
Highlighted
User Moderator
User Moderator

As a debugging aid, you could insert a Get-Module just before the cmdlet


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

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

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

0 Kudos
Highlighted
User Moderator
User Moderator

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


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

0 Kudos
Highlighted
Hot Shot
Hot Shot

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?

0 Kudos
Highlighted
User Moderator
User Moderator

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

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

0 Kudos
Highlighted
Hot Shot
Hot Shot

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

pastedImage_0.png

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.

0 Kudos