Showing posts with label PowerCLI. Show all posts
Showing posts with label PowerCLI. Show all posts

Wednesday 10 April 2019

Invoke-NSXWebRequest in PowerCLI

From a few days, I was trying to use Invoke-NSXWebRequest to make a RESTApi Call in PowerCLI.

I was not sure how to do this at once, Learning something is always good. I know I am not that good at scripting, but at least I know how to get my work done.
Not every cmdlet is available in POWERNSX  as of now, but nowadays EVERYTHING IS API & API IS EVERYTHING.

So here I have enabled high availability for NSX Edge using POWERNSX & RESTAPI


from NSXRestAPI Documentation  following syntax


 where method type is PUT



Defined a Variable named $Body and passed onto the given content.





Monday 1 January 2018

Encrypted password to login to vCenter in POWERCLI


$Password = Read-Host -Prompt "Enter Password" -AsSecureString
$DecodedPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password))
Connect-VIServer -Server vcsa-a.vclass.local -User administrator@vsphere.local -Password $DecodedPassword




Thursday 14 December 2017

Turn ON/OFF SSH on All ESXi host in vCenter/Cluster


$AllEsxi = get-vmhost
$AllEsxi | get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy ON
$Allesxi| Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService 


Output:-

  • First, we declare a variable $AllEsxi which stores result from Get-VMhost & then we are enabling SSH on all the given hosts.
  • If you want to turn OFF the SSH on all the hosts, simply replace ON with OFF and run the command.
  • To turn off & stop the service on all the host.


$AllEsxi | Get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy OFF
$Allesxi| Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Stop-VMHostService 


  • If you want to do it at Cluster level, then specify the cluster variable or then use the following:-
$Cluster_Host = Get-Cluster MyCluster | Get-VMHost
$Cluster_Host | get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy ON
$Cluster_Host | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Start-VMHostService 

  • If you want to turn ON/OFF service at cluster level, then specify the cluster variable or use the following:-
$Cluster_Host  | Get-VMhostService | where {$_.key -eq "TSM-SSH"} | Set-VMHostService -Policy OFF
$Cluster_Host  | Get-VMHostService | where {$_.key -eq "TSM-SSH"} | Stop-VMHostService 




    Sunday 15 October 2017

    vSAN Policies with PowerCLI(FTT=1,Stripe=3, Object Space Reservation = 50%)


    New-SpbmStoragePolicy -Name OBS -AnyOfRuleSets (New-SpbmRuleSet (New-SpbmRule -Capability (Get-SpbmCapability -Name "VSAN.hostfailuresToTolerate") -Value 1), (New-SpbmRule -Capability (Get-SpbmCapability -Name "VSAN.stripeWidth") -Value 3),(New-SpbmRule -Capability (Get-SpbmCapability -Name VSAN.proportionalCapacity)-Value 50))



    Output:-


    vSAN Policies with PowerCLI(FTT=1, RAID5/6)


    New-SpbmStoragePolicy -Name PowerCLI-RAID5  ` -AnyOfRuleSets ` (New-SpbmRuleSet ` (New-SpbmRule -Capability (Get-SpbmCapability -Name "VSAN.hostFailuresToTolerate" ) -Value 1),(New-SpbmRule -Capability (Get-SpbmCapability -Name "VSAN.replicaPreference" ) -Value "RAID-5/6 (Erasure Coding) - Capacity"))



    Output:-


    vSAN Policies with PowerCLI(Striping=3)


    New-SpbmStoragePolicy -Name Stripe=3 -RuleSet(New-SpbmRuleSet -Name "striping=3" -AllOfRules @((NewSpbmRule -Capability VSAN.stripewidth 3)))


    Output:-


    vSAN Policies with PowerCLI (No redundancy i.e FTT=0)


    New-SpbmStoragePolicy -Name FTT=0 -RuleSet(New-SpbmRuleSet -Name "NoRedundancy" -AllOfRules @((New-SpbmRule -Capability VSAN.hostFailuresToTolerate 0)))



    Output:-