vRo Action Apply VM Hostprofile with Powershell

var psScript = “
psScript +=‘ $esxHost = „‚ + esxHost.name + ‚“\n‘;
psScript +=‘ $profileName = „‚ + profileName + ‚“\n‘;
psScript +=‘ $userName = „‚ + userName + ‚“\n‘;
psScript +=‘ $passwd = „‚ + passwd + ‚“\n‘;
psScript +=‘ $vCenter = „‚ + vCenter.name.split(„/“)[2].split(„:“)[0] + ‚“\n‘;

psScript +=’try\n‘;
psScript +='{\n‘;
psScript +=‘ if($(Get-PSSnapin) -like \’VMWare.VimAutomation.Core\‘)\n‘;
psScript +=‘ {\n‘;
psScript +=‘ Write-Host „Already loaded \’VMWare.VimAutomation.Core\'“\n‘;
psScript +=‘ }\n‘;
psScript +=‘ else\n‘;
psScript +=‘ {\n‘;
psScript +=‘ Write-Host „Load \’VMWare.VimAutomation.Core\'“\n‘;
psScript +=‘ Add-PSSnapin \’VMWare.VimAutomation.Core\’\n‘;
psScript +=‘ }\n‘;
psScript +=‘ \n‘;
psScript +=‘ Connect-VIServer $vCenter -User $userName -Password $passwd | Out-Null \n‘;
psScript +=‘ Apply-VMHostProfile -Entity $esxHost -Profile $profileName -Confirm:$false \n‘;
psScript +=‘}\n‘;

psScript +=’catch\n‘;
psScript +='{\n‘;
psScript +=‘ Write-Host „## Exception ##“\n‘;
psScript +=‘ Write-Host $_.Exception.Message\n‘;
psScript +=‘ Write-Host „—-„\n‘;
psScript +=‘ Write-Host $_.Exception.Stacktrace\n‘;
psScript +=‘ Write-Host „###############“\n‘;
psScript +=‘}\n‘;
psScript +=’finally\n‘;
psScript +='{\n‘;
psScript +=‘ Disconnect-VIServer -Confirm:$false | Out-Null \n‘;
psScript +=‘}\n‘;
return System.getModule(„com.vmware.library.powershell“).invokeScript( host,psScript,sessionId) ;

         

hferch has written 76 articles

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">