- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it was working fine yesterday .today its not :smileyplain:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you change PowerCLI versions in between?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i am going to check this again .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i see a different weired issue the comand new-contentlibrary is avaliable but i cant use inside function.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As a debugging aid, you could insert a Get-Module just before the cmdlet
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
oh you are right .just remember in order to have get-contentlibrary command available
i just added import-module vmware.vimautomation.core -force
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Does that mean that modules do not autoload in your setup?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.