Thursday, April 20, 2023

Brocade switch reboot process

 

Description

Use this command to perform a "cold reboot" (power off/restart) of the control processor. This operation may be disruptive, and the command prompts for confirmation before executing. When you reboot a switch connected to a fabric, all traffic to and from that switch stops. All Fibre Channel ports on that switch including E_Ports become inactive until the switch comes back online.
The behavior of this command depends on the platform:
  • When issued on a standalone (single-processor) switch, this command performs a cold reboot of the switch.
  • When issued on an enterprise-class platform (Brocade X6-4 Director or Brocade X6-8 Director) with two CPs (active and standby), the following rules apply:
    • When the Standby CP reboots, it goes down and there is no failover because there is no traffic on that switch. When the Standby CP comes up again, it is temporarily no longer in sync with the Active CP.
    • When the Active CP reboots, it fails over to the Standby CP. The Standby CP becomes the new Active CP and traffic is disrupted.
    • When HA is in sync, and 
      reboot -f
       is issued on the Active CP of a director, the Standby CP takes over as the active CP without traffic disruption. If HA is not in sync, and 
      reboot -f
       is issued on the Active CP, the Standby CP takes over as the Active CP and traffic is disrupted.
    • When HA is disabled and 
      reboot
       or 
      reboot -f
       is issued on the Active CP, both the Active and Standby CPs reboot with the original mastership retained. The original Active CP remains the Active CP after the reboot, and the original Standby CP remains the Standby CP. After the reboot, HA is enabled.
    • When HA is disabled and 
      reboot
       or 
      reboot -f
       is issued on the Standby CP, the Standby CP reboots without prompting. It boots up with the default switch only, even if the Active CP has multiple logical switches configured. After the Standby CP boots up, HA is still disabled.

Notes

This command is subject to Virtual Fabric restrictions that may be in place. See "Using Fabric OS Commands" and "Command Availability" for details.

Operands

-f
Causes the CP to fail over to the Standby CP without affecting any of the Fibre Channel Ports. Note that the recommended way to force a failover without affecting any Fibre Channel ports is to issue the 
haFailover
 command.

Examples

To reboot a standalone switch with a single CP:
switch:admin>
reboot
Warning: This command would cause the switch to reboot
and result in traffic disruption.
Are you sure you want to reboot the switch [y/n]?
y
Rebooting! Sun Feb 28 19:49:45 2010...
The system is going down for reboot NOW !!
To reboot a CP when HA is enabled:
switch:admin>
reboot
Warning: This command is being run on a control processor (CP)
based system and will cause the active CP to reboot.
Are you sure you want to reboot the active CP [y/n]?
y
Rebooting! Sun Feb 28 19:49:45 2010...
The system is going down for reboot NOW !!
To reboot a CP when 
haFailover
 is disabled:
switch:admin>
reboot
This command is being run on a control processor (CP)
based system. Because HA is disabled, it will cause both
active CP and the standby CP to reboot. After reboot, the
HA will be enabled.
Do you want to continue [y/n]
y
Rebooting! Sun Feb 28 19:49:45 2010...
The system is going down for reboot NOW !!

Tuesday, February 14, 2023

Azure Powershell commands

- To connect azure subscription from powershell.


Connect-AzAccount 

- if Connect-AzAccount does not connect properly use below command.

Connect-AzAccount -DeviceCode

WARNING: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code D3DWL7T2R to authenticate.

- Type below command to check available subscription.

Get-AzSubscription

- To switch the subscription use below command.

Set-AzContext -Subscription {293caa52-ebff-42e6-9e6f-xxxxxxxx subscription id}

once you switch the subscription you can check resource of that subscription.


- Use below command to check resource group

Get-AzResourceGroup

use below to check formated info about resource group.

Get-AzResource | Format-Table

- use below command to create vm instance

New-AzVm -ResourceGroupName learn-6d075fba-929b-432a-89c7-xxxxxxx -Name "testvm-eus-01" -Credential (Get-Credential) -Location "eastus" -Image Canonical:0001-com-ubuntu-server-focal:20_04-lts:latest -OpenPorts 22 -PublicIpAddressName "testvm-01"




Wednesday, March 2, 2022

To change ESXi root user description via Vcenter Power cli.

 To change ESXi root user description via Vcenter Power cli.


# csv file should have heading with ESXi, username, password

$csv = Import-csv .\esxi.csv

foreach ($line in $csv)

{

Connect-VIServer -Server $($line.ESXi) -User $($line.username) -Password $($line.password) -WarningAction silentlyContinue


Get-VMHostAccount -User root | Set-VMHostAccount -Description admin6 -Confirm:$false | Out-Null -ErrorAction SilentlyContinue


Disconnect-VIServer -Server $($line) -Confirm:$false


}

Tuesday, February 1, 2022

Powershell script to collect VM info from Vcenter

# Script: ListVMs.ps1 - Ravi - 1st Feb 2022 
# Usage  : .\listvms <vcenter or host ip>:[Manadatory] <user>:[Manadatory] <password>:[Manadatory] <sortBy>:[Optional]
# Example: .\listvms 192.168.0.1 root mypassword ramalloc
#
# Desc   : Retrieves a list of virtual machines from an ESXi host or vCenter Server, extracting a subset of 
#          vm properties values returned by Get-View. The list is converted to HTML and written to disk. 
#          The script automatically displays the report by invoking the default browser.

#Command line parameters
[CmdletBinding()]
Param(
 [Parameter(Mandatory=$true,Position=1)]
 [string]$hostIP,
 
 [Parameter(Mandatory=$false,Position=2)]
 [string]$user,
 
 [Parameter(Mandatory=$false,Position=3)]
 [string]$pass,
 
 [Parameter(Mandatory=$false,Position=4)]
 [string]$sortBy
)

#Populate PSObject with the required vm properties 
function vmProperties
{
 param([PSObject]$view)
 
 $list=foreach ($vm in $view){
 
 #Get net info
  $ips=$vm.guest.net.ipaddress
  $macs=$vm.guest.net.MacAddress
 
 #State info
  if ($vm.Runtime.PowerState -eq "poweredOn") {$state="ON"}
   elseif ($vm.Runtime.PowerState -eq "poweredOff") {$state="OFF"}
    else {$state="n/a"}
 
 #VMtools state
  if ($vm.summary.guest.ToolsRunningStatus -eq "guestToolsRunning") {$vmtools="Running"}
   elseif ($vm.summary.guest.ToolsRunningStatus -eq "guestToolsNotRunning") {$vmtools="Not running"}
    else {$vmtools="n/a"}
 
 #Check for multi-homed vms - max. 2 ips
  if ($ips.count -gt 1)
  {$ips=$vm.guest.net.ipaddress[0] + " " + $vm.guest.net.ipaddress[1]} 
 
  if ($macs.count -gt 1)
   {$macs=$vm.guest.net.macaddress[0] + " " + $vm.guest.net.macaddress[1]} 
 
 #Populate object
 [PSCustomObject]@{
  "Name" = $vm.Name
  "Cluster" = ($vms | Get-Cluster).Name
  "OS" = $vm.Guest.GuestFullName
  "Hostname" = $vm.summary.guest.hostname
  "vCPUs" = $vm.Config.hardware.NumCPU
  "Cores" = $vm.Config.Hardware.NumCoresPerSocket
  "RAM Alloc" = $vm.Config.Hardware.MemoryMB
  "RAM Host" = $vm.summary.QuickStats.HostMemoryUsage
  "RAM guest" = $vm.summary.QuickStats.GuestMemoryUsage
  "NICS" = $vm.Summary.config.NumEthernetCards
  "vmtoolversion" = $vm.Config.Tools.ToolsVersion
  "IPs" = $ips
  "MACs" = $macs
  "vmTools" = $vmtools
  "State" = $state
  "UUID" = $vm.Summary.config.Uuid
  "VM ID" = $vm.Summary.vm.value
  }
 }
 
 return $list
}

#Stylesheet - this is used by the ConvertTo-html cmdlet
function header{
 $style = @"
 <style>
 body{
 font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
 }
 
 table{
  border-collapse: collapse;
  border: none;
  font: 10pt Verdana, Geneva, Arial, Helvetica, sans-serif;
  color: black;
  margin-bottom: 10px;
 }
 
 table td{
  font-size: 10px;
  padding-left: 0px;
  padding-right: 20px;
  text-align: left;
 }
 
 table th{
  font-size: 10px;
  font-weight: bold;
  padding-left: 0px;
  padding-right: 20px;
  text-align: left;
 }
 
 h2{
  clear: both; font-size: 130%;color:#00134d;
 }
 
 p{
  margin-left: 10px; font-size: 12px;
 }
 
 table.list{
  float: left;
 }
 
 table tr:nth-child(even){background: #e6f2ff;} 
 table tr:nth-child(odd) {background: #FFFFFF;}

 div.column {width: 320px; float: left;}
 div.first {padding-right: 20px; border-right: 1px grey solid;}
 div.second {margin-left: 30px;}

 table{
  margin-left: 10px;
 }
 –>
 </style>
"@

 return [string] $style
 }

#############################
### Script entry point ###
#############################

#Path to html report
 $repPath=(gci env:userprofile).value+"\desktop\test.htm"

#Report Title
 $title = "<h2>VMs hosted on $hostIP</h2>"

#Sort by
 if ($sortBy -eq "") {$sortBy="Name"; $desc=$False} 
  elseif ($sortBy.Equals("ramalloc")) {$sortBy = "RAM Alloc"; $desc=$True} 
   elseif ($sortBy.Equals("ramhost")) {$sortBy = "RAM Host"; $desc=$True} 
    elseif ($sortBy.Equals("os")) {$sortBy = "OS"; $desc=$False}

Try{
 #Drop any previously established connections
  Disconnect-VIServer -Confirm:$False -ErrorAction SilentlyContinue
 
 #Connect to vCenter or ESXi
  if (($user -eq "") -or ($pass -eq "")) 
   {Connect-VIServer $hostIP -ErrorAction Stop}
  else 
    {Connect-VIServer $hostIP -User $user -Password $pass -ErrorAction Stop}

 #Get a VirtualMachine view of all vms
  $vmView = Get-View -viewtype VirtualMachine
  $vms = Get-VM
 
 #Iterate through the view object, write the set of vm properties to a PSObject and convert the whole lot to HTML
  (vmProperties -view $vmView) | Sort-Object -Property @{Expression=$sortBy;Descending=$desc} | ConvertTo-Html -Head $(header) -PreContent $title | Set-Content -Path $repPath -ErrorAction Stop
 
 #Disconnect from vCenter or ESXi
  Disconnect-VIServer -Confirm:$False -Server $hostIP -ErrorAction Stop
 
 #Load report in default browser
  Invoke-Expression "cmd.exe /C start $repPath"
 }
Catch
 {
  Write-Host $_.Exception.Message
 }

Tuesday, June 15, 2021

Powershell script to collect OS details

Powershell script to collect OS details

##################################################
$ipaddress=Get-Content -Path C:\ry\ansible\ip.txt
#$ErrorActionPreference='silentlycontinue'
$results = @()

ForEach ($i in $ipaddress)
 {
$sess = New-PSSession -ComputerName $i
$osname=Invoke-Command -Session $sess -ScriptBlock {(gwmi win32_operatingsystem).caption}
$osbit=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).OSArchitecture}
$hostname=Invoke-Command -Session $sess -ScriptBlock {(Get-WmiObject Win32_OperatingSystem).CSName}
$hItemDetails=[pscustomobject]@{
Hostname=$hostname
OS_Name=$osname
OS_bit=$osbit
}
$results +=$hItemDetails
}

$results | Export-Csv C:\ry\ansible\machinenames.csv

#############################################################

Monday, June 14, 2021

Powershell Ping report status script

Ping report status script

$result= @()
$names = Get-Content "c:\ip2.txt"
foreach ($name in $names){
  if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
   $Output= "up"
#   Write-Host "up" -ForegroundColor Green
  }
  else{
    $Output= "down"
#    Write-Host "down" -ForegroundColor Red
  }
$hItemDetails=[pscustomobject]@{
IP_address=$name
Status=$Output
}
$result +=$hItemDetails
}
$result | Export-Csv "c:\result2.csv"

Sunday, June 13, 2021

Ansible playbook to delete selected VMs from file.

Ansible playbook to delete selected VMs from file.

####################### delete selected VMs#######################


---
- name: Delete VMs from Vcenter
  hosts: localhost
  gather_facts: no
  vars:
    hostname: 192.168.0.x
    username: administrator@vsphere.local
    password: abcd@1234
  tasks:
  - name: Delete Vms
    vmware_guest:
      hostname: "{{ hostname }}"
      username: "{{ username }}"
      password: "{{ password }}"
      validate_certs: False
      name: "{{ item }}"
      state: absent
      wait_for_ip_address: no
    delegate_to: localhost
    with_lines: cat vmname.txt