Wednesday, May 14, 2014

PowerCLI - Initial connection script commands

Connecting to a server:


                connect-VIserver -server 192.168.10.10 -credential $credential
                                    connect-VIserver -server 192.168.10.10 -protocol http
Connecting to multiple servers:  connect-VIserver -server 192.168.10.10 -credential $credential -ALLlinked

List all connected vCenters:  connect-VIserver -Menu

Connect to multiple vCenters:  connect-VIserver -server vCenter1,vCenter2,vCenter3

Current configuration mode: get-PowerCLIConfiguration
Set configuration mode: single or multple vCenters
set-PowerCliconfiguration
set-PowerCliconfiguration -DefaultVIServermode signle -scope user

The servers are stored in $global:DefaultServer

Suppress Certificate warnings
set-PowerCliConfiguration -InvalidCertificateAction Ignore



NFS Datastore

Mount

New-Datastore -VMHost abc.xyz.com -Nfs -Name Test -NfsHost nfsinterface.isilon.com -Path /ifs/datastore/templates

Remove Mount

Get-VMHost | Remove-Datastore -Datastore templates


Configure DNS Address

Get-VMHostNetwork | Get-VMHost | Set-VMHostNetwork -DomainName test.abc.com -DNSAddress  10.10.10.10, 10.20.20.20

Get-VMHostNetwork -VMHost host.test.abc.com | Set-VMHostNetwork -DomainName test.abc.com -DNSAddress 10.10.10.10, 10.20.20.20

Configure Syslog Datastore

Get-VMHost | Set-AdvancedSetting -NameValue @{'Config.HostAgent.log.level'='info';'Vpx.Vpxa.config.log.level'='info';'Syslog.global.logHost'='udp://sysng-te.test.statefarm.com:514'}


Create NFS adapters:

New-VMHostNetworkAdapter -VMHost host.abc.com -PortGroup INFR_ISILON_VLAN11 -VirtualSwitch switchname  -IP 10.10.10.10 -SubnetMask 255.255.255.0 -MTU 9000



Disconnect from Servers:

disconnect-VIserver -server * -Force


Get Credentials:

get-VIcredentialStoreItem

some useful links: hostilecoding.blogspot.com/2014/03/vmware-powercli-to-report-triggered.html
https://www.simple-talk.com/sysadmin/virtualization/10-steps-to-kick-start-your-vmware-automation-with-powercli/


Restarting Powerpath Watch dog service


Get-VMHost -name corpesx2g.test.statefarm.com | Get-VMHostService | where {$_.Key -match "sfcbd-watchdog"} | Restart-VMHostService -Confirm:$false


Enable and disable lock down mode on ESXi Host

(get-vmhost $ESXhost | get-view).ExitLockdownMode() # To DISABLE Lockdown Mode
(get-vmhost $ESXhost | get-view).EnterLockdownMode() # To ENABLE Lockdown Mode


Script for running commands across all hosts in vcenter

$vCenter = 'vCenterServer_Name_or_IP_address'
Connect-VIServer $vCenter
$Scope = Get-VMHost #This will change the Lockdown Mode on all hosts managed by vCenter
foreach ($ESXhost in $Scope) {
(get-vmhost $ESXhost | get-view).ExitLockdownMode() # To DISABLE Lockdown Mode

Get-VMHost -name corpesx2g.test.statefarm.com | Get-VMHostService | where {$_.Key -match "sfcbd-watchdog"} | Restart-VMHostService -Confirm:$false

#(get-vmhost $ESXhost | get-view).EnterLockdownMode() # To ENABLE Lockdown Mode
}

Disconnect-VIServer -Server $vCenter -Confirm:$false







No comments:

Post a Comment