Showing posts with label All about scripts. Show all posts
Showing posts with label All about scripts. 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.





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 




    Monday 24 April 2017

    Installing PowerShell & PowerCLI in MAC OS

    Mac Install 

    Install These are the detailed instructions. 

    Step 1 - Download PowerShell for MAC and need to check whether it allows you to install if gives you an error related to the unidentified application. To resolve this, click the Apple symbol in the menu bar and open System Preferences > Security & Privacy and then click Open Anyway.
    Installed will be there and install.

    Step 2 - Make sure you did not miss this step from the PowerShell installation instruction:

    brew install openssl brew install curl --with-openssl 

    Step 3 - Create the following directory if it does not exists by running the following command: 

    mkdir -p ~/.local/share/powershell/Modules 

    Step 4 - Extract the PowerCLI modules into the directory you created above by running the following command: 

    unzip PowerCLI.ViCore.zip -d ~/.local/share/powershell/Modules 
    unzip PowerCLI.Cis.zip -d ~/.local/share/powershell/Modules 
    unzip PowerCLI.Vds.zip -d ~/.local/share/powershell/Modules