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.