вторник, 21 февраля 2023 г.

Extract ESXi iDrac and BIOS versions and their IPs with PowerCLI

 cls

$viserver = "vCenter"

$User = "USER"

$Pass = "PASSWORD"

Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue | Out-Null

$UnsortedVMHosts = (Get-VMHost).name

$VMHostNames = $UnsortedVMHosts | sort #  | select -First 3

$Array = @()

Write-Host


foreach($ESXiName in $VMHostNames)

    {

    Connect-VIServer -Server $viserver -User $User -Password $Pass

    $OneLineArray = New-Object "PSCustomObject"

    

    $ESXiName

    $VMHost = Get-VMHost $ESXiName

    $VMView = $VMHost | Get-View

    $BiosInfo = $VMView.Hardware.BiosInfo

        

    $Vendor = $VMHost.ExtensionData.Hardware.SystemInfo.Vendor

    $Model = $VMHost.ExtensionData.Hardware.SystemInfo.Model

    $BiosVersion = $BiosInfo.BiosVersion

    $ReleaseDate = $BiosInfo.ReleaseDate

    $EsxIP = (Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel -Name vmk0).IP

    $EsxiVer = $VMHost.ExtensionData.Config.Product.FullName

    $vCenter = $VMHost.ExtensionData.Client.ServiceContent.About.FullName


    Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue

    Connect-VIServer -Server $ESXiName -User root -Password "PASSWORD" # | Out-Null

    Connect-VIServer -Server $ESXiName -User Administrator -Password "PASSWORD" # | Out-Null

    $esxcli = Get-EsxCli -VMHost $ESXiName -V2

    $iDracIP = $esxcli.hardware.ipmi.bmc.get.Invoke().IPv4Address

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "ESXiName" -Value $ESXiName

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "Vendor" -Value $Vendor

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "Model" -Value $Model

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "BiosVersion" -Value $BiosVersion

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "ReleaseDate" -Value $ReleaseDate

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "EsxIP" -Value $EsxIP

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "iDracIP" -Value $iDracIP

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "EsxiVer" -Value $EsxiVer

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "vCenter" -Value $vCenter

    $Array += $OneLineArray

    }

$Array | OGV -Title "ESXi Hosts"

$Array | Export-Csv "C:\Temp\ESXiHosts-report.csv" -NoTypeInformation -UseCulture

ii "C:\Temp\report.csv"

    

Import VMs from vCenter to vCloud vApp with PowerCLI

cls

#  Import VMs from vCenter to vCloud vApp with PowerCLI

$SourceFolder = "SOURCE"

$DestVApp = "DEST_VAPP"

$VIserver = 'VCENTER.DOMAIN.COM"

$CIserver = 'VCLOUD.DOMAIN.COM"

$UVI = "VCENTER_USER"

$PVI = "VCENTER_PASSWORD"

$UCI = "VCLOUD_USER"

$PCI = "VCLOUD_PASSWORD"

Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue | Out-Null

Connect-VIServer -Server $VIserver -User $UVI -Password $PVI

Disconnect-CIServer * -Confirm:$false -ErrorAction SilentlyContinue

Connect-CIServer -Server $CIserver -User $UCI -Password $PCI

$VMs = Get-Folder $SourceFolder | Get-VM | sort 

$CIvappObj = Get-CIVApp $DestVApp

foreach ($VM in $VMs) 

    {

    $VM.name

    $CIvappObj | Import-CIVApp -VM $vm -NoCopy:$False -RunAsync -Confirm $false

    }


среда, 1 февраля 2023 г.

wget-in-Windows

Sometimes we want to use Linux command in Windows.

One of them is wget - an easy way to download sites and pages from the Internet.
There is also cURL.

Do we have them in Windows?
Natively, no, but...

The 1st way - PowerShell has command Invoke-WebRequest.

# Using PowerShell for getting a Google page:
Invoke-WebRequest http://www.google.com/ -OutFile c:\google.html
# or
Invoke-WebRequest http://www.google.com/ | -OutFile c:\google.html

# Using wget as an alias for Invoke-WebRequest (not a real wget)
wget http://www.google.com/ -OutFile c:\google.html
wget http://www.google.com/ | -OutFile c:\google.html

# Showing the results
ii c:\google.html

The 2nd way - we can install wget as a regular program - as an exe file or with Chocolatey.
Chocolatey is an extremely powerful tool with a large range of features and options.
Here is a good site about Chocolatey:
https://howchoo.com/chocolatey/install-pc-programs-using-powershell-and-chocolatey

Let's see the installation with Chocolatey.

# First install Chocolatey with PowerShell (what you see is one long line in PowerShell):
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

This will tell your system to download Chocolatey from the web and install it.
You can upgrade Chocolatey itself by running this command:
choco upgrade chocolatey



Then you can install wget with Chocolatey from PowerShell or even from a regular CMD.
choco install wget

# Use wget to pull a website to your local machine
wget --mirror --convert-links --adjust-extension --page-requisites c:\google.html





Installing Chocolatey

Chocolatey is a program or method for installing packages/programs/application in Windows in the simple way.

For installing Chocolatey we need to use PowerShell command:

 Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

All this is one long line.