├── README.md ├── get-LUNinfo.ps1 ├── set-multipath.ps1 ├── VMinfo.ps1 ├── VMReport.ps1 ├── OVVolumeBuild.ps1 ├── add-stdportgroup.ps1 ├── alarms.ps1 ├── BuildNimbleDatastore.ps1 ├── PSVMReport.ps1 ├── OVNimbleDatastore.ps1 ├── OVNimbleDataStoreBuild.ps1 ├── NUMAReport.ps1 ├── PatchCompliance.ps1 ├── import.ps1 ├── export.ps1 ├── NUMAReportcsv.ps1 ├── Move-CrossVC.ps1 ├── ADinfo.ps1 ├── FormMove-CrossVC.ps1 ├── show-menu.ps1 └── LICENSE /README.md: -------------------------------------------------------------------------------- 1 | # Powershell/Powercli scripts 2 | -------------------------------------------------------------------------------- /get-LUNinfo.ps1: -------------------------------------------------------------------------------- 1 | 2 | $VC = read-host "Enter vCenter name or IP address" 3 | 4 | Connect-Viserver $VC 5 | 6 | Write-Host "Gather LUN info" -ForegroundColor Yellow 7 | # Get VMFS volumes. Ignore local SCSILuns. 8 | Get-VMHost | Get-ScsiLun | Sort-Object VMhost | Select-Object VMHost, CanonicalName, CapacityGB, Vendor, MultipathPolicy, LunType, IsLocal, IsSsd, @{n='LunID';E={ 9 | 10 | $esxcli = Get-EsxCli -VMHost $_.VMHost -V2 11 | 12 | $esxcli.storage.nmp.path.list.Invoke(@{'device'=$_.CanonicalName}).RuntimeName.Split(':')[-1].TrimStart('L')}} | 13 | Sort-Object -Property {[int]$_.LUN} | Export-Csv C:\Temp\Luns.csv -NoTypeInformation 14 | 15 | Disconnect-viserver -server * -confirm:$false 16 | -------------------------------------------------------------------------------- /set-multipath.ps1: -------------------------------------------------------------------------------- 1 | #Setting Storage Luns to Round Robin 2 | $VC = Read-Host " Enter vCenter name:" 3 | 4 | Connect-VIServer $VC 5 | 6 | Get-Cluster | Select name | FT 7 | $Cluster = Read-Host " Enter Cluster name fron list above:" 8 | 9 | $VMhosts = Get-cluster $cluster | Get-VMHost 10 | Foreach ($VMhost in $VMhosts) { 11 | Write-Host "Setting Multipath Policy on $VMhost to Round Robin" -ForegroundColor Green 12 | Get-VMHost $VMhost | Get-ScsiLun -LunType disk | Where {$_.MultipathPolicy-notlike "RoundRobin"} | Set-Scsilun -MultiPathPolicy RoundRobin 13 | Get-VMhost $VMhost | Get-ScsiLun -LunType Disk | Where-Object {$_.CanonicalName-like ‘naa.*’ -and $_.MultipathPolicy-like ‘RoundRobin’} | Set-ScsiLun -CommandsToSwitchPath 1 14 | } 15 | 16 | Write-host "disconnecting from $VC" -ForegroundColor Yellow 17 | Disconnect-VIServer -Server * -Confirm:$False 18 | -------------------------------------------------------------------------------- /VMinfo.ps1: -------------------------------------------------------------------------------- 1 | $VC = read-host " Enter vCenter Name" 2 | Connect-viserver $VC 3 | 4 | #Add VM properties for vmtools version 5 | Write-Host "Adding VM Properties for vmtools" -ForegroundColor Yellow 6 | New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force 7 | New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' -Force 8 | 9 | 10 | #Get VM info 11 | Write-Host "Gathering VM info" -ForegroundColor Yellow 12 | get-cluster | Get-VM | Select Name, @{N="IP Address";E={@($_.guest.IPAddress[0])}}, @{N='FQDN';E={$_.ExtensionData.Guest.IPStack[0].DnsConfig.HostName, $_.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}}, Guest, Version, ToolsVersion, ToolsVersionStatus, PowerState, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB | Export-Csv F:\Powercli\Inventory\VMinfo.csv -NoTypeInformation 13 | 14 | disconnect-viserver -Server * -Confirm:$false -------------------------------------------------------------------------------- /VMReport.ps1: -------------------------------------------------------------------------------- 1 | #Enter the vCenter or ESXi name or ip 2 | $vc = Read-Host "Enter vCenter or ESXi name or IP address" 3 | Connect-VIServer $vc 4 | 5 | #Add VM properties for vmtools version 6 | Write-Host "Adding VM Properties for vmtools" -ForegroundColor Yellow 7 | New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force 8 | New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' -Force 9 | 10 | #Get VM info 11 | Write-Host "Gathering VM info" -ForegroundColor Yellow 12 | get-cluster | Get-VM | Select Name, Folder, @{N="IP Address";E={@($_.guest.IPAddress[0])}}, @{N='FQDN';E={$_.ExtensionData.Guest.IPStack[0].DnsConfig.HostName, $_.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}}, Guest, Version, ToolsVersion, ToolsVersionStatus, PowerState, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB | Export-Csv C:\Temp\VMinfo.csv -NoTypeInformation 13 | 14 | Write-host "Spreadsheet is located at C:\temp\VMinfo.csv" -ForegroundColor Green 15 | 16 | Disconnect-viserver -server * -confirm:$false 17 | -------------------------------------------------------------------------------- /OVVolumeBuild.ps1: -------------------------------------------------------------------------------- 1 | Write-host "Enter OneView password at the prompt" -ForegroundColor Yellow 2 | Connect-HPOVMgmt -Hostname "" -UserName "" 3 | $VC = Read-Host "Enter vCenter name/ip to connect to" -ForegroundColor Cyan 4 | Connect-viserver $VC 5 | 6 | Get-HPOVStoragePool 7 | Write-host "For the next two questions refer to the data on screen" -ForegroundColor Yellow 8 | $Pool = Read-host "Enter the name of the Storage Pool to use for the new volume" 9 | $System = Read-Host "Enter the name of the Storage System that Pool is on" 10 | $cap = Read-host "Enter the size of the volume in GB" 11 | $name = Read-Host "Enter the name of the new volume" 12 | $ID = Read-Host "Enter the Lun ID fo rthe new volume" 13 | $cluster = Read-Host "Enter VMware cluster to add datastore" 14 | 15 | $SP = Get-HPOVStoragePool -Name $Pool -StorageSystem $System 16 | New-HPOVStorageVolume -Name $name -StoragePool $SP -Capacity $cap -ProvisioningType Thin 17 | 18 | $vol = Get-HPOVStorageVolume -Name $name 19 | # the *CA1ESX* will get all the host in the shared production cluster 20 | # use *Tenant* to get all the host in the Cloud environment 21 | $blades = Get-HPOVServerProfile -Name *CA1ESX* 22 | Foreach ($svr in $blades) { 23 | New-HPOVServerProfileAttachVolume -ServerProfile $profile -Volume $vol -LunID $ID -LunIdType Manual | Wait-HPOVTaskComplete 24 | } 25 | #scan all the host in the cluster to new storage volume 26 | Get-Cluster $cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs 27 | -------------------------------------------------------------------------------- /add-stdportgroup.ps1: -------------------------------------------------------------------------------- 1 | $VC = Read-Host " Enter vCenter name:" 2 | Connect-VIServer $VC   3 | $VMHosts = Get-cluster "Production" | Get-VMHost 4 | foreach ($VMHost in $VMHosts) { 5 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-219 -VLanId 219 6 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-1201 -VLanId 1201 7 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-1300 -VLanId 1300 8 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-217 -VLanId 217 9 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-103 -VLanId 103 10 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-104 -VLanId 104 11 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-105 -VLanId 105 12 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-106 -VLanId 106 13 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-107 -VLanId 107 14 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-112 -VLanId 112 15 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-118 -VLanId 118 16 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-2000 -VLanId 2000 17 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-2001 -VLanId 201 18 | Get-VMHost -name $VMhost | Get-VirtualSwitch -name vswitch2 | New-VirtualPortGroup -name Name-1207 -VLanId 1207 19 | }  20 | Disconnect-viserver -Server * -Confirm:$false ‍ 21 | -------------------------------------------------------------------------------- /alarms.ps1: -------------------------------------------------------------------------------- 1 | $VC = Read-Host "Enter vCenter Name/IP" 2 | Connect-Viserver $VC 3 | 4 | 5 | #Gather VM Active Alerts 6 | $VMs = Get-View -ViewType VirtualMachine -Property Name,OverallStatus,TriggeredAlarmstate 7 | $FaultyVMs = $VMs | Where-Object {$_.OverallStatus -ne "Green"} 8 | 9 | $progress = 1 10 | $report = @() 11 | if ($FaultyVMs -ne $null) { 12 | foreach ($FaultyVM in $FaultyVMs) { 13 | foreach ($TriggeredAlarm in $FaultyVM.TriggeredAlarmstate) { 14 | Write-Progress -Activity "Gathering alarms" -Status "Working on $($FaultyVM.Name)" -PercentComplete ($progress/$FaultyVMs.count*100) -Id 1 -ErrorAction SilentlyContinue 15 | $alarmID = $TriggeredAlarm.Alarm.ToString() 16 | $object = New-Object PSObject 17 | Add-Member -InputObject $object NoteProperty VM $FaultyVM.Name 18 | Add-Member -InputObject $object NoteProperty TriggeredAlarms ("$(Get-AlarmDefinition -Id $alarmID)") 19 | $report += $object 20 | } 21 | $progress++ 22 | } 23 | } 24 | Write-Progress -Activity "Gathering Active VM alarms" -Status "All done" -Completed -Id 1 -ErrorAction SilentlyContinue 25 | 26 | $report | Where-Object {$_.TriggeredAlarms -ne ""} |Export-Csv C:\Temp\vmAlert.csv -NoTypeInformation 27 | 28 | #Gather vHost Active Alerms 29 | Write-host "Gathering Active vHost Alarms" -ForegroundColor Yellow 30 | $esx_all = Get-VMHost | Get-View 31 | $Report=@() 32 | foreach ($esx in $esx_all){ 33 | foreach($triggered in $esx.TriggeredAlarmState){ 34 | If ($triggered.OverallStatus -like "red" ){ 35 | $lineitem={} | Select Name, AlarmInfo 36 | $alarmDef = Get-View -Id $triggered.Alarm 37 | $lineitem.Name = $esx.Name 38 | $lineitem.AlarmInfo = $alarmDef.Info.Name 39 | $Report+=$lineitem 40 | } 41 | } 42 | } 43 | $Report |Sort Name | Export-Csv C:\Temp\HostAlarms.csv -NoTypeInformation 44 | 45 | Disconnect-viserver -Server * -Confirm:$false 46 | -------------------------------------------------------------------------------- /BuildNimbleDatastore.ps1: -------------------------------------------------------------------------------- 1 | #connect to Nimble, be sure to add your Nimble IP or FQDN in the "" 2 | Write-Host "Connecting to Nimble" -ForegroundColor Green 3 | Connect-NSGroup "" -IgnoreServerCertificate -Credential admin 4 | 5 | #VMWare performance policy ID 6 | $id = "0366971348fab73f4b000000000000000000000014" 7 | 8 | #Initiator Groups (per host) 9 | $CMH001 = "0266971348fab73f4b000000000000000000000007" 10 | $CMH002 = "0266971348fab73f4b000000000000000000000008" 11 | $CMH003 = "0266971348fab73f4b000000000000000000000009" 12 | $CMH004 = "0266971348fab73f4b00000000000000000000000a" 13 | 14 | $name = Read-Host "Enter Datastore Name" 15 | $size = Read-Host "Enter Datastore Size in MB" 16 | 17 | New-NSVolume -name $name -size $size -perfpolicy_id $id -thinly_provisioned $true -online $true 18 | 19 | #remove charactors in the volume id so they are usable 20 | $vol = Get-NSvolume -name "test2" | select ID 21 | $id = $vol -replace "@{id=","" -replace "}", "" 22 | 23 | #add new volume to initiator groups 24 | New-NSAccessControlRecord -vol_id $id -apply_to both -initiator_group_id $CMH001 -lun 4 25 | New-NSAccessControlRecord -vol_id $id -apply_to both -initiator_group_id $CMH002 -lun 4 26 | New-NSAccessControlRecord -vol_id $id -apply_to both -initiator_group_id $CMH003 -lun 4 27 | New-NSAccessControlRecord -vol_id $id -apply_to both -initiator_group_id $CMH004 -lun 4 28 | 29 | #connect to vmware to create datastore 30 | Write-host "Connecting to vCenter" -ForegroundColor Green 31 | Connect-viserver 192.168.151.2 -User administrator@vsphere.local 32 | 33 | #rescan host for new storage 34 | Get-VMHost | Get-VMHostStorage -RescanAllHba -Refresh 35 | 36 | #function to find free LUNs found at http://vcloud-lab.com/entries/powercli/find-free-or-unassigned-storage-lun-disks-on-vmware-esxi-server 37 | # removed some of the notes to save space 38 | function Get-FreeEsxiLUNs { 39 | #EXAMPLE 40 | #Get-FreeEsxiLUNs -Esxihost Esxi001.vcloud-lab.com 41 | #Shows free unassigned storage Luns disks on Esxi host name Esxi001.vcloud-lab.com 42 | ############################### 43 | 44 | [CmdletBinding()] 45 | param( 46 | [Parameter(Position=0, Mandatory=$true)] 47 | [System.String]$Esxihost 48 | ) 49 | Begin { 50 | if (-not(Get-Module vmware.vimautomation.core)) { 51 | Import-Module vmware.vimautomation.core 52 | } 53 | #Connect-VIServer | Out-Null 54 | } 55 | Process { 56 | $VMhost = Get-VMhost $EsxiHost 57 | $AllLUNs = $VMhost | Get-ScsiLun -LunType disk 58 | $Datastores = $VMhost | Get-Datastore 59 | foreach ($lun in $AllLUNs) { 60 | $Datastore = $Datastores | Where-Object {$_.extensiondata.info.vmfs.extent.Diskname -Match $lun.CanonicalName} 61 | if ($Datastore.Name -eq $null) { 62 | $lun | Select-Object CanonicalName, CapacityGB, Vendor 63 | } 64 | } 65 | } 66 | End {} 67 | } 68 | 69 | $free = Get-FreeEsxiLUNs -Esxihost (get-vmhost | Get-random) | Where-Object {$_.Vendor -eq "Nimble"} |select CanonicalName 70 | $path = $free -replace "@{CanonicalName=","" -replace "}","" 71 | 72 | 73 | #create new Datastore 74 | Get-VMHost| Get-Random | New-Datastore -name "test" -Path $path -Vmfs -FileSystemVersion 6 75 | 76 | #rescan vhost for new Datastore 77 | Get-VMHost | Get-VMHostStorage -RescanAllHba -Refresh 78 | 79 | #Disconnect from Nimble and vCenter 80 | Disconnect-NSGroup 81 | Disconnect-VIServer -Server * -confirm:$false 82 | -------------------------------------------------------------------------------- /PSVMReport.ps1: -------------------------------------------------------------------------------- 1 | param ([System.Management.Automation.SwitchParameter] $PassThru) 2 | 3 | 4 | Import-Module PScribo -Force; 5 | 6 | $ReportName = "Virtual Machine Inventory Report" 7 | $CompanyName = Read-Host "Enter Company Name" 8 | $Author = Read-Host "Enter Author Name" 9 | $Version = Read-Host "Enter Version Number" 10 | $vc = Read-Host "Enter vCenter Name/IP" 11 | #$creds = Get-Credential 12 | $name = "$CompanyName $ReportName" 13 | 14 | <# The document name is used in the file output #> 15 | $document = Document $name -Verbose { 16 | <# Enforce uppercase section headers/names 17 | Enable automatic section numbering 18 | Set the page size to US Letter with 0.5inch margins #> 19 | $DefaultFont = 'Calibri' 20 | 21 | #region VMware Document Style 22 | DocumentOption -EnableSectionNumbering -PageSize Letter -DefaultFont $DefaultFont -MarginLeftAndRight 71 -MarginTopAndBottom 71 23 | 24 | Style -Name 'Title' -Size 24 -Color '002538' -Align Center 25 | Style -Name 'Title 2' -Size 18 -Color '007CBB' -Align Center 26 | Style -Name 'Title 3' -Size 12 -Color '007CBB' -Align Left 27 | Style -Name 'Heading 1' -Size 16 -Color '007CBB' 28 | Style -Name 'Heading 2' -Size 14 -Color '007CBB' 29 | Style -Name 'Heading 3' -Size 12 -Color '007CBB' 30 | Style -Name 'Heading 4' -Size 11 -Color '007CBB' 31 | Style -Name 'Heading 5' -Size 10 -Color '007CBB' 32 | Style -Name 'H1 Exclude TOC' -Size 16 -Color '007CBB' 33 | Style -Name 'Normal' -Size 10 -Color '565656' -Default 34 | Style -Name 'TOC' -Size 16 -Color '007CBB' 35 | Style -Name 'TableDefaultHeading' -Size 10 -Color 'FAF7EE' -BackgroundColor '002538' 36 | Style -Name 'TableDefaultRow' -Size 10 37 | Style -Name 'TableDefaultAltRow' -Size 10 -BackgroundColor 'D9E4EA' 38 | Style -Name 'Critical' -Size 10 -BackgroundColor 'FFB38F' 39 | Style -Name 'Warning' -Size 10 -BackgroundColor 'FFE860' 40 | Style -Name 'Info' -Size 10 -BackgroundColor 'A6D8E7' 41 | Style -Name 'OK' -Size 10 -BackgroundColor 'AADB1E' 42 | 43 | TableStyle -Id 'TableDefault' -HeaderStyle 'TableDefaultHeading' -RowStyle 'TableDefaultRow' -AlternateRowStyle 'TableDefaultAltRow' -BorderColor '002538' -Align Left -BorderWidth 0.5 -Default 44 | TableStyle -Id 'Borderless' -BorderWidth 0 45 | 46 | # VMware Cover Page 47 | BlankLine -Count 5 48 | Paragraph -Style Title $ReportName 49 | Paragraph -Style Title2 "Prepared for $CompanyName" 50 | BlankLine -Count 36 51 | Table -Name 'Cover Page' -List -Style Borderless -Width 0 -Hashtable ([Ordered] @{ 52 | 'Author:' = $Author 53 | 'Date:' = Get-Date -Format 'dd MMMM yyyy' 54 | 'Version:' = $Version 55 | }) 56 | 57 | PageBreak; 58 | 59 | # Table of Contents 60 | TOC -Name 'Table of Contents' 61 | PageBreak; 62 | 63 | Connect-VIServer $vc 64 | Section -Style Heading2 'Virtual Machine' { 65 | #Add VM properties for vmtools version 66 | Write-Host "Adding VM Properties for vmtools" -ForegroundColor Yellow 67 | New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine -ValueFromExtensionProperty 'Config.tools.ToolsVersion' -Force 68 | New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine -ValueFromExtensionProperty 'Guest.ToolsVersionStatus' -Force 69 | 70 | #Get VM info 71 | Write-Host "Gathering VM info" -ForegroundColor Yellow 72 | $VMS = get-cluster | Get-VM | Select Name, Folder, @{N="IP Address";E={@($_.guest.IPAddress[0])}}, @{N='FQDN';E={$_.ExtensionData.Guest.IPStack[0].DnsConfig.HostName, $_.ExtensionData.Guest.IPStack[0].DnsConfig.DomainName -join '.'}}, Guest, Version, ToolsVersion, ToolsVersionStatus, PowerState, NumCpu, MemoryGB, ProvisionedSpaceGB, UsedSpaceGB | Sort-Object Folder 73 | 74 | $VMS |Table -List -Name 'Virtual Machines' -ColumnWidths 25,75 75 | 76 | } 77 | 78 | } 79 | $document | Export-Document -Path ~\Desktop -Format Word,Html -PassThru:$PassThru -Verbose; 80 | 81 | 82 | Disconnect-VIServer -Server * -Confirm:$false 83 | -------------------------------------------------------------------------------- /OVNimbleDatastore.ps1: -------------------------------------------------------------------------------- 1 | Write-host "Enter OneView password at the prompt" -ForegroundColor Yellow 2 | Connect-HPOVMgmt -Hostname 192.168.219.70 -UserName hpadmin 3 | $VC = Read-Host "Enter vCenter name/ip to connect to" 4 | Connect-viserver $VC 5 | 6 | $Pool = "default" 7 | $System = "Edafio-Cloud" 8 | $cap = Read-host "Enter the size of the volume in GB" 9 | $name = Read-Host "Enter the name of the new volume" 10 | $ID = Read-Host "Enter the Lun ID for the new volume" 11 | $cluster = "HPC" 12 | 13 | $policy = Get-HPOVStorageSystem -Name $system | Show-HPOVStorageSystemPerformancePolicy -Name "VMware ESX 5" 14 | $SP = Get-HPOVStoragePool -Name $Pool -StorageSystem $System 15 | #create volume 16 | Write-Host " Creating new volume named $name with $cap gb of storage" -ForegroundColor Cyan 17 | New-HPOVStorageVolume -Name $name -StoragePool $SP -Capacity $cap -ProvisioningType Thin -PerformancePolicy $policy -Shared | Wait-HPOVTaskComplete 18 | 19 | 20 | $vol = Get-HPOVStorageVolume -Name $name 21 | 22 | Write-host " Connecting the new volume $name to the HPC Server profiles" -ForegroundColor Cyan 23 | $blades = Get-HPOVServerProfile -Name *HPC* 24 | Foreach ($svr in $blades) { 25 | New-HPOVServerProfileAttachVolume -ServerProfile $svr -Volume $vol -LunID $ID -LunIdType Manual | Wait-HPOVTaskComplete 26 | } 27 | #scan all the host in the cluster to new storage volume 28 | 29 | Sleep 10 30 | Write-host " connecting to $cluster cluster and scanning for new storage" -ForegroundColor Yellow 31 | Get-Cluster $cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs 32 | 33 | #function to find free LUNs found at http://vcloud-lab.com/entries/powercli/find-free-or-unassigned-storage-lun-disks-on-vmware-esxi-server 34 | # removed some of the notes to save space 35 | function Get-FreeEsxiLUNs { 36 | #EXAMPLE 37 | #Get-FreeEsxiLUNs -Esxihost Esxi001.vcloud-lab.com 38 | #Shows free unassigned storage Luns disks on Esxi host name Esxi001.vcloud-lab.com 39 | ############################### 40 | 41 | [CmdletBinding()] 42 | param( 43 | [Parameter(Position=0, Mandatory=$true)] 44 | [System.String]$Esxihost 45 | ) 46 | Begin { 47 | if (-not(Get-Module vmware.vimautomation.core)) { 48 | Import-Module vmware.vimautomation.core 49 | } 50 | #Connect-VIServer | Out-Null 51 | } 52 | Process { 53 | $VMhost = Get-VMhost $EsxiHost 54 | $AllLUNs = $VMhost | Get-ScsiLun -LunType disk 55 | $Datastores = $VMhost | Get-Datastore 56 | foreach ($lun in $AllLUNs) { 57 | $Datastore = $Datastores | Where-Object {$_.extensiondata.info.vmfs.extent.Diskname -Match $lun.CanonicalName} 58 | if ($Datastore.Name -eq $null) { 59 | $lun | Select-Object CanonicalName, CapacityGB, Vendor 60 | } 61 | } 62 | } 63 | End {} 64 | } 65 | 66 | $free = Get-FreeEsxiLUNs -Esxihost (Get-cluster $cluster |get-vmhost | Get-random) | Where-Object {$_.Vendor -eq "Nimble"} |select CanonicalName 67 | $path = $free -replace "@{CanonicalName=","" -replace "}","" 68 | 69 | 70 | #create new Datastore 71 | Write-host " Creating new Datastore named $name in cluster $cluster" -ForegroundColor Cyan 72 | Get-cluster $cluster |get-vmhost | Get-random| New-Datastore -name $name -Path $path -Vmfs -FileSystemVersion 6 73 | 74 | #rescan vhost for new Datastore 75 | Get-VMHost | Get-VMHostStorage -RescanAllHba -Refresh 76 | 77 | #Create Datastore Tag and Storage policy for vCloud Director 78 | Write-Host "Creating Datastore Tag and Storage Policy for vCloud Director" -ForegroundColor Yellow 79 | $tag = New-Tag -Name $name -Category Datastore 80 | $rule = New-SpbmRule -AnyOfTags $tag 81 | $ruleset = New-SpbmRuleSet -AllOfRules $rule 82 | $policy = New-SpbmStoragePolicy -Name $name -AnyOfRuleSets $ruleset 83 | Get-Datastore -Server $VC -Name $name | New-TagAssignment -Tag $tag 84 | 85 | Write-Host "Volume $name has been created and attached to vmware cluster $cluster" -ForegroundColor Green 86 | Write-host "Disconnecting from OneView and vCenter" -ForegroundColor Green 87 | Disconnect-HPOVMgmt 88 | Disconnect-VIServer -Server * -Confirm:$false 89 | -------------------------------------------------------------------------------- /OVNimbleDataStoreBuild.ps1: -------------------------------------------------------------------------------- 1 | $HPOV = Read-host "Enter the OneView Server name /IP" 2 | $HPOVUsr = Read-Host "Enter your OneView User name" 3 | Write-host "Enter OneView password at the prompt" -ForegroundColor Yellow 4 | Connect-HPOVMgmt -Hostname $HPOV -UserName $HPOVUsr 5 | $VC = Read-Host "Enter vCenter name/ip to connect to" 6 | Connect-viserver $VC 7 | 8 | Get-HPOVStoragePool 9 | Write-host "For the next two questions refer to the data on screen" -ForegroundColor Yellow 10 | $Pool = Read-host "Enter the name of the Storage Pool to use for the new volume" 11 | $System = Read-Host "Enter the name of the Storage System that Pool is on" 12 | $cap = Read-host "Enter the size of the volume in GB" 13 | $name = Read-Host "Enter the name of the new volume" 14 | $ID = Read-Host "Enter the Lun ID for the new volume" 15 | $cluster = Read-Host "Enter VMware cluster to add datastore" 16 | 17 | $policy = Get-HPOVStorageSystem -Name $system | Show-HPOVStorageSystemPerformancePolicy -Name "VMware ESX 5" 18 | $SP = Get-HPOVStoragePool -Name $Pool -StorageSystem $System 19 | #create volume 20 | Write-Host " Creating new volume named $name with $cap gb of storage" -ForegroundColor Cyan 21 | New-HPOVStorageVolume -Name $name -StoragePool $SP -Capacity $cap -ProvisioningType Thin -PerformancePolicy $policy -Shared | Wait-HPOVTaskComplete 22 | 23 | 24 | $vol = Get-HPOVStorageVolume -Name $name 25 | 26 | Write-host " Connecting the new volume $name to the HPC Server profiles" -ForegroundColor Cyan 27 | $blades1 = Get-HPOVServerProfile -Name *HPC* 28 | $blades2 = Get-HPOVServerProfile -Name *Tenant* 29 | Foreach ($svr in $blades1) { 30 | New-HPOVServerProfileAttachVolume -ServerProfile $svr -Volume $vol -LunID $ID -LunIdType Manual | Wait-HPOVTaskComplete 31 | } 32 | 33 | Foreach ($svr in $blades2) { 34 | New-HPOVServerProfileAttachVolume -ServerProfile $svr -Volume $vol -LunID $ID -LunIdType Manual | Wait-HPOVTaskComplete 35 | } 36 | #scan all the host in the cluster to new storage volume 37 | 38 | Sleep 20 39 | Write-host " connecting to $cluster and scanning for new storage" -ForegroundColor Yellow 40 | Get-Cluster $cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba -RescanVmfs 41 | 42 | #function to find free LUNs found at http://vcloud-lab.com/entries/powercli/find-free-or-unassigned-storage-lun-disks-on-vmware-esxi-server 43 | # removed some of the notes to save space 44 | function Get-FreeEsxiLUNs { 45 | #EXAMPLE 46 | #Get-FreeEsxiLUNs -Esxihost Esxi001.vcloud-lab.com 47 | #Shows free unassigned storage Luns disks on Esxi host name Esxi001.vcloud-lab.com 48 | ############################### 49 | 50 | [CmdletBinding()] 51 | param( 52 | [Parameter(Position=0, Mandatory=$true)] 53 | [System.String]$Esxihost 54 | ) 55 | Begin { 56 | if (-not(Get-Module vmware.vimautomation.core)) { 57 | Import-Module vmware.vimautomation.core 58 | } 59 | #Connect-VIServer | Out-Null 60 | } 61 | Process { 62 | $VMhost = Get-VMhost $EsxiHost 63 | $AllLUNs = $VMhost | Get-ScsiLun -LunType disk 64 | $Datastores = $VMhost | Get-Datastore 65 | foreach ($lun in $AllLUNs) { 66 | $Datastore = $Datastores | Where-Object {$_.extensiondata.info.vmfs.extent.Diskname -Match $lun.CanonicalName} 67 | if ($Datastore.Name -eq $null) { 68 | $lun | Select-Object CanonicalName, CapacityGB, Vendor 69 | } 70 | } 71 | } 72 | End {} 73 | } 74 | 75 | $free = Get-FreeEsxiLUNs -Esxihost (Get-cluster $cluster |get-vmhost | Get-random) | Where-Object {$_.Vendor -eq "Nimble"} |select CanonicalName 76 | $path = $free -replace "@{CanonicalName=","" -replace "}","" 77 | 78 | 79 | #create new Datastore 80 | Write-host " Creating new Datastore named $name in cluster $cluster" -ForegroundColor Cyan 81 | Get-VMHost | Get-Random | New-Datastore -name $name -Path $path -Vmfs -FileSystemVersion 6 82 | 83 | #rescan vhost for new Datastore 84 | Get-VMHost | Get-VMHostStorage -RescanAllHba -Refresh 85 | 86 | #Create Datastore Tag and Storage policy for vCloud Director 87 | Write-Host "Creating Datastore Tag and Storage Policy for vCloud Director" -ForegroundColor Yellow 88 | $tag = New-Tag -Name $name -Category Datastore 89 | $rule = New-SpbmRule -AnyOfTags $tag 90 | $ruleset = New-SpbmRuleSet -AllOfRules $rule 91 | $policy = New-SpbmStoragePolicy -Name $name -AnyOfRuleSets $ruleset 92 | Get-Datastore -Server $VC -Name $name | New-TagAssignment -Tag $tag 93 | 94 | 95 | 96 | 97 | Write-Host "Volume $name has been created and attached to vmware cluster $cluster" -ForegroundColor Green 98 | Write-host "Disconnecting from OneView and vCenter" -ForegroundColor Green 99 | Disconnect-HPOVMgmt 100 | Disconnect-VIServer -Server * -Confirm:$false 101 | -------------------------------------------------------------------------------- /NUMAReport.ps1: -------------------------------------------------------------------------------- 1 | #Get vCenter name and Connect 2 | Write-host "" 3 | $vc = Read-Host "Enter vCenter name to conenct to" 4 | Write-Host "" 5 | Write-host "Connecting to $vc, Login prompt to follow.." -ForegroundColor Cyan 6 | Connect-VIServer $vc 7 | 8 | #Get list of all clusters in vCenter 9 | $Clusters = Get-Cluster 10 | ForEach ($c in $Clusters){ 11 | Write-host "Processing Cluster $c..." -ForegroundColor Magenta 12 | Write-host "" 13 | 14 | #Process each host in cluster 15 | $NUMAStats = @() 16 | $largeMemVM = @() 17 | $largeCPUVM = @() 18 | 19 | $hosts = Get-VMHost -Location $c 20 | 21 | ForEach ($h in $Hosts) { 22 | $HostView = $h | Get-View 23 | $HostSummary = “” | Select HostName, MemorySizeGB, CPUSockets, CPUCoresSocket, CPUCoresTotal, CPUThreads, NumNUMANodes, NUMANodeCPUSize, NUMANodeMemSize 24 | 25 | #Get Host CPU, Memory & NUMA info 26 | $HostSummary.HostName = $h.Name 27 | $HostSummary.MemorySizeGB =([Math]::Round($HostView.hardware.memorysize / 1GB)) 28 | $HostSummary.CPUSockets = $HostView.hardware.cpuinfo.numCpuPackages 29 | $HostSummary.CPUCoresSocket = ($HostView.hardware.cpuinfo.numCpuCores / $HostSummary.CPUSockets) 30 | $HostSummary.CPUCoresTotal = $HostView.hardware.cpuinfo.numCpuCores 31 | $HostSummary.CPUThreads = $HostView.hardware.cpuinfo.numCpuThreads 32 | $HostSummary.NumNUMANodes = $HostView.hardware.numainfo.NumNodes 33 | $HostSummary.NUMANodeCPUSize = ($HostSummary.CPUCoresTotal / $HostSummary.NumNUMANodes) 34 | $HostSummary.NUMANodeMemSize =([Math]::Round($HostSummary.MemorySizeGB / $HostSummary.NumNUMANodes)) 35 | $NUMAStats += $HostSummary 36 | } 37 | 38 | #Find the smallest NUMA Node (CPU & Mem) to use for comparison 39 | $x = $HostSummary.NUMANodeMemSize | measure -Minimum 40 | $y = $HostSummary.NUMANodeCPuSize | measure -Minimum 41 | 42 | #Get list of all VMs in cluster that are oversized 43 | $VMDeatils = @() 44 | $VMDeatils = Get-VM -Location $c | where {$_.NumCpu -gt $y.Minimum -or $_.MemoryGB -gt $x.Minimum} 45 | 46 | Write-host "Processing VM's in cluster for NUMA oversizing.." -ForegroundColor Magenta 47 | Write-host "" 48 | 49 | # VM Calculations 50 | #Large MEM VM - Any VM with more memory allocated then the NUMA node. 51 | $largeMemVM += $VMDeatils | Where-Object {$_.MemoryGB -gt $x.Minimum} 52 | 53 | #Large CPU VM - Any VM with more CPU then cores per Proc on a host 54 | $largeCPUVM += $VMDeatils | Where-Object {$_.NumCPU -gt $y.Minimum} 55 | 56 | #Display report for current cluster 57 | Write-Host "NUMA Node Specs for Cluster - $c." -ForegroundColor Yellow 58 | $NUMAStats | ft 59 | 60 | if ($largeMemVM -or $largeCPUVM) { 61 | if ($largeCPUVM) { 62 | Write-host $largeCPUVM.Count "VMs in $c that Exceed CPUCoresSocket." -ForegroundColor Cyan 63 | $largeCPUVM | select name, @{N='Memory GB';E={$_.MemoryGB}}, @{N='Num CPU';E={$_.ExtensionData.Config.Hardware.NumCPU}}, @{N='Num Sockets';E={($_.ExtensionData.Config.Hardware.NumCPU / $_.ExtensionData.Config.Hardware.NumCoresPerSocket)}}, @{N='Cores Per Socket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}}, @{N='CPU Hot Plug Status';E={$_.ExtensionData.Config.CpuHotAddEnabled}} | ft 64 | } 65 | Else { Write-host "All VM CPU allocations are within NUMA ranges" -ForegroundColor Green} 66 | 67 | if ($largeMemVM) { 68 | Write-host $largeMemVM.Count "VMs in $c that Exceed NUMA Node Memory size." -ForegroundColor Cyan 69 | $largeMemVM | select name, @{N='Memory GB';E={$_.MemoryGB}}, @{N='Num CPU';E={$_.ExtensionData.Config.Hardware.NumCPU}}, @{N='Num Sockets';E={($_.ExtensionData.Config.Hardware.NumCPU / $_.ExtensionData.Config.Hardware.NumCoresPerSocket)}}, @{N='Cores Per Socket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}}, @{N='CPU Hot Plug Status';E={$_.ExtensionData.Config.CpuHotAddEnabled}} | ft 70 | } 71 | Else { Write-host "All VM memory allocations are within NUMA ranges" -ForegroundColor Green} 72 | } 73 | Else { Write-Host "No VM's in Cluster - $c to report NUMA issues on" -ForegroundColor Green} 74 | Write-host "" 75 | Write-host "" 76 | } 77 | Write-Host "Disconnecting from $vc" -ForegroundColor Yellow 78 | Disconnect-viserver -Server $vc -Confirm:$false 79 | -------------------------------------------------------------------------------- /PatchCompliance.ps1: -------------------------------------------------------------------------------- 1 | $WSUS = Read-Host "Enter Name/IP of WSUS server" 2 | $VC = Read-Host "Enter vCenter Name/IP" 3 | $reportname = Read-Host "Enter Report Name" 4 | $CompanyName = Read-Host "Enter Company Name " 5 | $author = Read-Host "Enter Author Name" 6 | 7 | 8 | Connect-PSWSUSServer $WSUS -Port 8530 9 | Connect-VIServer $VC 10 | 11 | 12 | 13 | 14 | <# The document name is used in the file output #> 15 | $document = Document $ReportName -Verbose { 16 | <# Enforce uppercase section headers/names 17 | Enable automatic section numbering 18 | Set the page size to US Letter with 0.5inch margins #> 19 | $DefaultFont = 'Calibri' 20 | 21 | #region VMware Document Style 22 | DocumentOption -EnableSectionNumbering -PageSize Letter -DefaultFont $DefaultFont -MarginLeftAndRight 40 -MarginTopAndBottom 50 23 | 24 | Style -Name 'Title' -Size 22 -Color '002538' -Align Center 25 | Style -Name 'Title 2' -Size 18 -Color '007CBB' -Align Center 26 | Style -Name 'Title 3' -Size 12 -Color '007CBB' -Align Left 27 | Style -Name 'Heading 1' -Size 16 -Color '007CBB' 28 | Style -Name 'Heading 2' -Size 14 -Color '007CBB' 29 | Style -Name 'Heading 3' -Size 12 -Color '007CBB' 30 | Style -Name 'Heading 4' -Size 11 -Color '007CBB' 31 | Style -Name 'Heading 5' -Size 10 -Color '007CBB' 32 | Style -Name 'H1 Exclude TOC' -Size 16 -Color '007CBB' 33 | Style -Name 'Normal' -Size 10 -Color '565656' -Default 34 | Style -Name 'TOC' -Size 16 -Color '007CBB' 35 | Style -Name 'TableDefaultHeading' -Size 10 -Color 'FAF7EE' -BackgroundColor '002538' 36 | Style -Name 'TableDefaultRow' -Size 10 37 | Style -Name 'TableDefaultAltRow' -Size 10 -BackgroundColor 'D9E4EA' 38 | Style -Name 'Critical' -Size 10 -BackgroundColor 'FFB38F' 39 | Style -Name 'Warning' -Size 10 -BackgroundColor 'FFE860' 40 | Style -Name 'Info' -Size 10 -BackgroundColor 'A6D8E7' 41 | Style -Name 'OK' -Size 10 -BackgroundColor 'AADB1E' 42 | 43 | TableStyle -Id 'TableDefault' -HeaderStyle 'TableDefaultHeading' -RowStyle 'TableDefaultRow' -AlternateRowStyle 'TableDefaultAltRow' -BorderColor '002538' -Align Left -BorderWidth 0.5 -Default 44 | TableStyle -Id 'Borderless' -BorderWidth 0 45 | 46 | # VMware Cover Page 47 | BlankLine -Count 4 48 | Paragraph -Style Title $ReportName 49 | Paragraph -Style Title2 "Prepared for $CompanyName" 50 | BlankLine -Count 36 51 | Table -Name 'Cover Page' -List -Style Borderless -Width 0 -Hashtable ([Ordered] @{ 52 | 'Author:' = $author 53 | 'Date:' = Get-Date -Format 'dd MMMM yyyy' 54 | 'Version:' = Get-date -Format 'yyyyMM' 55 | }) 56 | 57 | PageBreak; 58 | 59 | # Table of Contents 60 | TOC -Name 'Table of Contents' 61 | PageBreak; 62 | Section -Style Heading1 ". Windows Server Patch Compliance" { 63 | Paragraph "This Section shows the patch compliance of the Windows servers in the Edafio Cloud Management Cluster" 64 | Get-PSWSUSUpdateSummaryPerClient |Select Computer, Installed, Needed, Failed, PendingReboot, NotApplicable, LastUpdated | Sort-Object Computer| Table 65 | Blankline} 66 | PageBreak; 67 | 68 | Section -Style Heading1 ". VMware Host Patch Compliance" { 69 | Paragraph "This Section shows the patch compliance of the VMware Host in the Edafio Cloud " 70 | $clusters = Get-Cluster 71 | $BL = Get-Baseline -Name "HP Host" -BaselineType Patch 72 | 73 | Foreach ($Cluster in $Clusters) { 74 | Section -Style Heading3 " $cluster Cluster Compliance" { 75 | 76 | Write-host "Compliance for $cluster Cluster" -ForegroundColor Yellow 77 | Test-Compliance -Entity $cluster -UpdateType HostPatch 78 | Get-Compliance -Entity $cluster -Baseline $BL -Detailed | Select-object Entity, @{N=’Baseline’;E={$_.Baseline.Name}}, Status, @{N=’CompliantPatches’;E={$_.CompliantPatches.Length}}, @{N=’NotCompliantPatches’;E={$_.NotCompliantPatches.Length}},@{N=’UnknownPatches’;E={$_.UnknownPatches.Length}}, @{N=’NotApplicablePatches’;E={$_.NotApplicablePatches.Length}} | Table 79 | Blankline} 80 | PageBreak; 81 | } 82 | } 83 | Section -Style Heading1 ". Missing VMware Host Patches" { 84 | Paragraph "This Section shows what patches are missing from the VMware Host in the Edafio Cloud " 85 | $esx = Get-VMHost |Get-Random 86 | 87 | Test-Compliance -Entity $esx -UpdateType HostPatch 88 | 89 | $report = $esx | Get-Compliance -Detailed | %{ 90 | 91 | $_.NotCompliantPatches | 92 | 93 | Select-Object Name,IDByVendor,Description,@{n='Product';e={$_.product | Select-Object -expandproperty Version}},ReleaseDate 94 | 95 | } 96 | 97 | 98 | 99 | $report |Table 100 | BlankLine} 101 | PageBreak; 102 | } 103 | $document | Export-Document -Path ~\Desktop -Format Word,Html -PassThru:$PassThru -Verbose; 104 | 105 | Disconnect-PSWSUSServer 106 | Disconnect-VIServer -Server * -Confirm:$False 107 | 108 | -------------------------------------------------------------------------------- /import.ps1: -------------------------------------------------------------------------------- 1 | $VC = Read-Host "Enter vCenter Name /IP" 2 | Connect-VIServer -$VC 3 | 4 | 5 | 6 | param 7 | ( 8 | $directory = $(read-host "Enter local input directory"), 9 | $datacenter = $(read-host "Enter datacenter"), 10 | [switch]$roles, 11 | [switch]$permissions, 12 | [switch]$folders, 13 | [switch]$vms 14 | ) 15 | 16 | function make-ParentFolder 17 | { 18 | Param 19 | ( 20 | $inFolderArray 21 | ) 22 | $parentFolder = get-datacenter $datacenter | get-folder "VM" 23 | foreach ($thisSubFolder in $inFolderArray) 24 | { 25 | if (!($parentFolder | get-folder $thisSubFolder -noRecursion -erroraction silentlycontinue)) 26 | { 27 | $ParentFolder = $parentFolder | new-folder $thisSubFolder 28 | } 29 | else 30 | { 31 | $ParentFolder = $ParentFolder | get-folder $thisSubFolder -noRecursion 32 | } 33 | } 34 | $ParentFolder 35 | } 36 | 37 | $directory = $directory.trim("\") #" fix the gistit syntax highlighting 38 | 39 | #Rebuild Folder Structure 40 | if ($folders) 41 | { 42 | $folderArray = import-clixml $directory\$($datacenter)-folders.xml 43 | $i = 0 44 | foreach ($thisFolder in $folderArray) 45 | { 46 | write-progress -Activity "Creating Folders" -percentComplete ($i / $folderArray.count * 100) 47 | make-ParentFolder -inFolderArray $thisFolder.path 48 | $i++ 49 | } 50 | } 51 | 52 | #Rebuild Roles 53 | if ($roles) 54 | { 55 | $allRoles = import-clixml $directory\$($datacenter)-roles.xml 56 | $i = 0 57 | foreach ($thisRole in $allRoles) 58 | { 59 | write-progress -Activity "Creating Roles" -percentComplete ($i / $allRoles.count * 100) 60 | if (!(get-virole $thisRole.name -erroraction silentlycontinue)) 61 | { 62 | new-virole -name $thisRole.name -privilege (get-viprivilege -id $thisRole.PrivilegeList) -erroraction silentlycontinue 63 | } 64 | $i++ 65 | } 66 | } 67 | 68 | #Rebuild Permissions 69 | if ($permissions) 70 | { 71 | $allPermissions = import-clixml $directory\$($datacenter)-permissions.xml 72 | $i = 0 73 | foreach ($thisPermission in $allPermissions) 74 | { 75 | write-progress -Activity "Creating Permissions" -percentComplete ($i / $allPermissions.count * 100) 76 | $target = "" 77 | if ($thisPermission.type -eq "Folder") 78 | { 79 | #permission is assigned to a folder, use make-folder to get the precise folder 80 | $target = make-Parentfolder -inFolderArray $thisPermission.entity 81 | } 82 | elseif ($thisPermission.type -eq "VirtualMachine") 83 | { 84 | #permission is assigned to VM 85 | $target = get-datacenter $datacenter | get-vm $thisPermission.entity 86 | } 87 | elseif ($thisPermission.type -eq "Datacenter") 88 | { 89 | #permission is assigned to Datacenter 90 | $target = get-datacenter $thisPermission.entity 91 | } 92 | else 93 | { 94 | write-error "Unexpected permission target, $($thisPermission.type)" 95 | } 96 | 97 | if ($target) 98 | { 99 | $target | new-vipermission -role $thisPermission.role -principal $thisPermission.principal -propagate $thisPermission.propagate 100 | } 101 | else 102 | { 103 | write-error "Unable to find permission object $($thisPermission.entity)" 104 | } 105 | $i++ 106 | } 107 | } 108 | 109 | #Replace VMs 110 | if ($VMs) 111 | { 112 | $allVMs = import-clixml $directory\$($datacenter)-VMs.xml 113 | $allVApps = $NULL 114 | $i = 0 115 | if (test-path $directory\vApps.xml){$allVApps = import-clixml $directory\$($datacenter)-vApps.xml} 116 | foreach ($thisVM in $allVMs) 117 | { 118 | write-progress -Activity "Placing VMs" -percentComplete ($i / $allVMs.count * 100) 119 | if ($foundVM = get-vm $thisVM.name) 120 | { 121 | $ParentFolder = make-ParentFolder -inFolderArray $thisVM.folderPath 122 | $foundVM | move-vm -destination $ParentFolder 123 | } 124 | $i++ 125 | } 126 | foreach ($thisVApp in $allVApps) 127 | { 128 | echo "===$($thisVApp.name)===" 129 | $thisvApp.VMs 130 | } 131 | #Convert Template VMs back to Templates 132 | } 133 | 134 | if (!($VMs -or $folders -or $permissions -or $roles)) 135 | { 136 | echo "Please use one or more of the -VMs, -Folders, -Permissions, or -Roles switches to do something" 137 | } 138 | 139 | 140 | 141 | Disconnect-VIServer -Server * -Confirm:$false -------------------------------------------------------------------------------- /export.ps1: -------------------------------------------------------------------------------- 1 | #$VC = Read-Host "Enter vCenter Name /IP" 2 | #Connect-VIServer -$VC 3 | 4 | #Get Data from Source vCenter 5 | #Built to be used with Set-SourceSettings.ps1 to recreate those same settings in another vCenter. 6 | #Does not support vApps or multiple datacenters in the same vCenter. 7 | param 8 | ( 9 | $directory = $(read-host "Enter local output directory"), 10 | $datacenter = $(read-host "Enter datacenter"), 11 | [switch]$getTemplates 12 | ) 13 | #Takes a VI Folder object and returns an array of strings that represents that folder's absolute path in the inventory 14 | function get-folderpath 15 | { 16 | param 17 | ( 18 | $thisFolder 19 | ) 20 | #Creates an array of folders back to the root folder 21 | if ($thisFolder.id -like "Folder*") 22 | { 23 | $folderArray = @() 24 | $folderArray += $thisFolder 25 | while ($folderArray[-1].parent.parent.id -match "Folder") 26 | { 27 | $folderArray += $folderArray[-1].parent 28 | } 29 | [array]::Reverse($folderArray) 30 | #convert the array of folders to an array of strings with just the folder names 31 | $folderStrArray = @() 32 | $folderArray | %{$folderStrArray += $_.name} 33 | $folderStrArray 34 | } 35 | else 36 | { 37 | write-error "Unexpected input provided; does not appear to be a Folder." 38 | } 39 | } 40 | 41 | $directory = $directory.trim("\") #" This comment is to fix the gistit syntax highlighting. 42 | new-item $directory -type directory -erroraction silentlycontinue 43 | 44 | if ((get-datacenter).count -gt 1){write-error "These scripts do not support multiple Datacenters in a single inventory"} 45 | 46 | #Get Roles 47 | get-virole | ? {$_.issystem -eq $false} | export-clixml $directory\$($datacenter)-roles.xml 48 | 49 | #Get Permissions 50 | $allPermissions = @() 51 | $foundPermissions = get-vipermission 52 | $i = 0 53 | foreach ($thisPermission in $foundPermissions) 54 | { 55 | write-progress -Activity "Getting permissions" -percentComplete ($i / $foundPermissions.count * 100) 56 | $objPerm = "" | select entity,type,Role,Principal,Propagate,folderType 57 | $objPerm.type = $thisPermission.entity.id.split("-")[0] 58 | $objPerm.Role = $thisPermission.role 59 | $objPerm.Principal = $thisPermission.Principal 60 | $objPerm.Propagate = $thisPermission.propagate 61 | #Create an absolute path for a folder, otherwise store the name of the entity 62 | if ($objPerm.type -eq "Folder") 63 | { 64 | $objPerm.entity = get-folderpath $thisPermission.entity 65 | $objPerm.folderType = $thisPermission.entity.type 66 | } 67 | else 68 | { 69 | $objPerm.entity = $thisPermission.entity.name 70 | $objPerm.folderType = "" 71 | } 72 | $allPermissions += $objPerm 73 | $i++ 74 | } 75 | $allPermissions | export-clixml $directory\$($datacenter)-permissions.xml 76 | 77 | 78 | #Get VM Folder Structure 79 | $outFolders = @() 80 | $i = 0 81 | $foundFolders = get-datacenter $datacenter | get-folder | ? {$_.type.tostring() -eq "VM" -and $_.parent.id -notLike "Datacenter*"} 82 | foreach ($thisFolder in $foundFolders) 83 | { 84 | write-progress -Activity "Getting VM folder structure" -percentComplete ($i / $foundFolders.count * 100) 85 | $myFolder = "" | select path 86 | $myFolder.path = get-folderpath $thisFolder 87 | $outFolders += $myFolder 88 | $i++ 89 | } 90 | $outFolders | export-clixml $directory\$($datacenter)-folders.xml 91 | 92 | #Convert Templates to VMs (so that they can transition vCenters) 93 | get-template | select name | export-clixml $directory\$($datacenter)-Templates.xml 94 | if ($getTemplates){get-datacenter $datacenter | get-template | set-template -ToVM -confirm:$false} 95 | 96 | #Get VM Locations 97 | $outVMs = @() 98 | $allVApps = get-datacenter $datacenter | get-vapp 99 | $vAppVMs = $allVApps | get-vm 100 | if ($vAppVMs) 101 | { 102 | $allVMs = Get-VM | ? {!($vAppVMs.contains($_))} 103 | #Deal with vApps... maybe try this guy's technique to capture settings and make a best effort at recreating the vApp? 104 | # http://www.lukaslundell.com/2013/06/modifying-vapp-properties-with-powershell-and-powercli/ 105 | $outVApps = @() 106 | foreach ($thisVApp in $allVApps) 107 | { 108 | write-error "Discovered VAPP: $($thisVApp.name) - vAPPs must be recreated manually." 109 | $myVApp = "" | select name,VMs 110 | $myVApp.name = $thisVApp.name 111 | $myVApp.VMs = ($thisVApp | get-vm).name 112 | $outVApps += $myVApp 113 | } 114 | $outVApps | export-clixml $directory\$($datacenter)-vApps.xml 115 | } 116 | else 117 | { 118 | $allVMs = get-datacenter $datacenter | get-VM 119 | } 120 | $i = 0 121 | foreach ($thisVM in $allVMs) 122 | { 123 | write-progress -Activity "Getting VM locations" -percentComplete ($i / $allVMs.count * 100) 124 | $myVM = "" | select name,folderPath 125 | $myVM.name = $thisVM.name 126 | if ($thisVM.folder.name -eq "VM") 127 | { 128 | $myVM.folderPath = $NULL 129 | } 130 | else 131 | { 132 | $myVM.folderPath = get-folderpath $thisVM.folder 133 | } 134 | $outVMs += $myVM 135 | $i++ 136 | } 137 | $outVMs | export-clixml $directory\$($datacenter)-VMs.xml 138 | 139 | 140 | Disconnect-VIServer -Server * -Confirm:$false 141 | -------------------------------------------------------------------------------- /NUMAReportcsv.ps1: -------------------------------------------------------------------------------- 1 | 2 | #Get vCenter name and Connect 3 | Write-host "" 4 | $vc = Read-Host "Enter vCenter name to conenct to" 5 | Write-Host "" 6 | Write-host "Connecting to $vc, Login prompt to follow.." -ForegroundColor Cyan 7 | Connect-VIServer $vc 8 | 9 | #Get list of all clusters in vCenter 10 | $Clusters = Get-Cluster 11 | ForEach ($c in $Clusters){ 12 | Write-host "Processing Cluster $c..." -ForegroundColor Magenta 13 | Write-host "" 14 | 15 | #Process each host in cluster 16 | $NUMAStats = @() 17 | $largeMemVM = @() 18 | $largeCPUVM = @() 19 | 20 | $hosts = Get-VMHost -Location $c 21 | 22 | ForEach ($h in $Hosts) { 23 | $HostView = $h | Get-View 24 | $HostSummary = “” | Select HostName, MemorySizeGB, CPUSockets, CPUCoresSocket, CPUCoresTotal, CPUThreads, NumNUMANodes, NUMANodeCPUSize, NUMANodeMemSize 25 | 26 | #Get Host CPU, Memory & NUMA info 27 | $HostSummary.HostName = $h.Name 28 | $HostSummary.MemorySizeGB =([Math]::Round($HostView.hardware.memorysize / 1GB)) 29 | $HostSummary.CPUSockets = $HostView.hardware.cpuinfo.numCpuPackages 30 | $HostSummary.CPUCoresSocket = ($HostView.hardware.cpuinfo.numCpuCores / $HostSummary.CPUSockets) 31 | $HostSummary.CPUCoresTotal = $HostView.hardware.cpuinfo.numCpuCores 32 | $HostSummary.CPUThreads = $HostView.hardware.cpuinfo.numCpuThreads 33 | $HostSummary.NumNUMANodes = $HostView.hardware.numainfo.NumNodes 34 | $HostSummary.NUMANodeCPUSize = ($HostSummary.CPUCoresTotal / $HostSummary.NumNUMANodes) 35 | $HostSummary.NUMANodeMemSize =([Math]::Round($HostSummary.MemorySizeGB / $HostSummary.NumNUMANodes)) 36 | $NUMAStats += $HostSummary 37 | } 38 | 39 | #Find the smallest NUMA Node (CPU & Mem) to use for comparison 40 | $x = $HostSummary.NUMANodeMemSize | measure -Minimum 41 | $y = $HostSummary.NUMANodeCPuSize | measure -Minimum 42 | 43 | #Get list of all VMs in cluster that are oversized 44 | $VMDeatils = @() 45 | $VMDeatils = Get-VM -Location $c | where {$_.NumCpu -gt $y.Minimum -or $_.MemoryGB -gt $y.Minimum} 46 | 47 | Write-host "Processing VM's in cluster for NUMA oversizing.." -ForegroundColor Magenta 48 | Write-host "" 49 | 50 | # VM Calculations 51 | #Large MEM VM - Any VM with more memory allocated then the NUMA node. 52 | $largeMemVM += $VMDeatils | Where-Object {$_.MemoryGB -gt $x.Minimum} 53 | 54 | #Large CPU VM - Any VM with more CPU then cores per Proc on a host 55 | $largeCPUVM += $VMDeatils | Where-Object {$_.NumCPU -gt $y.Minimum} 56 | 57 | #Display report for current cluster 58 | Write-Host "NUMA Node Specs for Cluster - $c." -ForegroundColor Yellow 59 | $NUMAStats | ft 60 | $NUMAStats| Export-Csv c:\temp\NUMA\"$C numa.csv" -NoTypeInformation 61 | 62 | if ($largeMemVM -or $largeCPUVM) { 63 | if ($largeCPUVM) { 64 | Write-host $largeCPUVM.Count "VMs in $c that Exceed CPUCoresSocket." -ForegroundColor Cyan 65 | $largeCPUVM | select name, @{N='Memory GB';E={$_.MemoryGB}}, @{N='Num CPU';E={$_.ExtensionData.Config.Hardware.NumCPU}}, @{N='Num Sockets';E={($_.ExtensionData.Config.Hardware.NumCPU / $_.ExtensionData.Config.Hardware.NumCoresPerSocket)}}, @{N='Cores Per Socket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}}, @{N='CPU Hot Plug Status';E={$_.ExtensionData.Config.CpuHotAddEnabled}} | ft 66 | $largeCPUVM |Export-Csv c:\temp\NUMA\"$C LargeCPUVM.csv" -NoTypeInformation 67 | } 68 | Else { Write-host "All VM CPU allocations are within NUMA ranges" -ForegroundColor Green} 69 | 70 | if ($largeMemVM) { 71 | Write-host $largeMemVM.Count "VMs in $c that Exceed NUMA Node Memory size." -ForegroundColor Cyan 72 | $largeMemVM | select name, @{N='Memory GB';E={$_.MemoryGB}}, @{N='Num CPU';E={$_.ExtensionData.Config.Hardware.NumCPU}}, @{N='Num Sockets';E={($_.ExtensionData.Config.Hardware.NumCPU / $_.ExtensionData.Config.Hardware.NumCoresPerSocket)}}, @{N='Cores Per Socket';E={$_.ExtensionData.Config.Hardware.NumCoresPerSocket}}, @{N='CPU Hot Plug Status';E={$_.ExtensionData.Config.CpuHotAddEnabled}} | ft 73 | $largeMemVM | Export-Csv c:\temp\NUMA\"$C LargeMEMVM.csv" -NoTypeInformation 74 | } 75 | Else { Write-host "All VM memory allocations are within NUMA ranges" -ForegroundColor Green} 76 | } 77 | Else { Write-Host "No VM's in Cluster - $c to report NUMA issues on" -ForegroundColor Green} 78 | Write-host "" 79 | Write-host "" 80 | } 81 | 82 | #Combine all csv's into single spreadsheet 83 | Write-Host "Compiling CSV's into a single spreadsheet" -ForegroundColor Yellow 84 | $path= "C:\temp\NUMA\*" 85 | $csvs = Get-ChildItem $path -Include *.csv 86 | $y=$csvs.Count 87 | Write-Host “Detected the following CSV files: ($y)” 88 | foreach ($csv in $csvs) 89 | { 90 | Write-Host ” “$csv.Name -ForegroundColor Green 91 | } 92 | $outputfilename = read-host “Please enter a name for the spreadsheet: ” 93 | $date = Get-Date -Format FileDate 94 | #$outputfilename = "Natco_Vmware_Health_Report_$date" 95 | Write-Host Creating: $outputfilename -ForegroundColor Green 96 | $excelapp = new-object -comobject Excel.Application 97 | $excelapp.sheetsInNewWorkbook = $csvs.Count 98 | $xlsx = $excelapp.Workbooks.Add() 99 | $sheet=1 100 | 101 | foreach ($csv in $csvs) 102 | { 103 | $row=1 104 | $column=1 105 | $worksheet = $xlsx.Worksheets.Item($sheet) 106 | $worksheet.Name = $csv.Name 107 | $file = (Get-Content $csv) 108 | foreach($line in $file) 109 | { 110 | $linecontents=$line -split ‘,(?!\s*\w+”)’ 111 | foreach($cell in $linecontents) 112 | { 113 | $cell = $cell.TrimStart(‘"‘) 114 | $cell = $cell.TrimEnd(‘"‘) 115 | $worksheet.Cells.Item($row,$column) = $cell 116 | $column++ 117 | } 118 | $column=1 119 | $row++ 120 | } 121 | $sheet++ 122 | } 123 | $output = "C:\temp\NUMA\Reports\$outputfilename.xlsx" 124 | $xlsx.SaveAs($output) 125 | $excelapp.quit() 126 | Write-Host "Done, Spreadsheet is located" $output -ForegroundColor Green 127 | 128 | Write-Host "Disconnecting from $vc" -ForegroundColor Yellow 129 | Disconnect-viserver -Server $vc -Confirm:$false 130 | 131 | -------------------------------------------------------------------------------- /Move-CrossVC.ps1: -------------------------------------------------------------------------------- 1 | Function Move-CrossVC 2 | { 3 | ######################################################################################################################################## 4 | # Move-CrossVC # 5 | # Updated by: Shane Moore 12/20/2019 # 6 | # Revision 1.1 12/26/2019 # 7 | # Revision 1.2 1/8/2019 # 8 | # Core code by VMware and the PSxVCvMotion module link here: https://code.vmware.com/samples/2060/psxvcvmotion---cross-vcenter-vmotion # 9 | ######################################################################################################################################## 10 | 11 | # making sure Pester is installed and Getting variable information 12 | Import-Module Pester 13 | $sourceVC = Read-Host " Enter Source vCenter Name" 14 | $DestVC = Read-Host " Enter Destination vCenter Name" 15 | $vmname = Read-host " Enter VM name to Migrate" 16 | $sourceCluster = Read-Host " Enter Source Cluster Name" 17 | $destCluster = Read-Host " Enter Destination Cluster Name" 18 | $sourcePG = Read-Host " Enter Source Port Group (Network) information" 19 | $DestPG = Read-Host " Enter Destination Port Group (Network) information" 20 | $destSwitch = Read-Host " Enter Destination Virtual Switch Name" 21 | $PG = $sourcePG, $DestPG 22 | $sourceDS = Read-Host " Enter Source Datastore" 23 | $destDS = Read-Host " Enter Destination DataStore" 24 | $DS = $sourceDS, $destDS 25 | 26 | # Clear Screen and start the stopwatch 27 | cls 28 | $StopWatch = New-Object -TypeName System.Diagnostics.Stopwatch 29 | $stopwatch.Start() 30 | 31 | #Creating connection to both vCenters 32 | Write-Host "Connecting to Source and Destination vCenters" -ForegroundColor Yellow 33 | Do { 34 | # Loop until we get a valid userid/password and can connect, or some other kind of error occurs 35 | $Cred = Get-Credential -Message "Enter $SourceVC Credentials" 36 | $ConResult = Connect-VIServer -Server $SourceVC -Credential $Cred -ErrorAction SilentlyContinue -ErrorVariable Err 37 | If ($Err.Count -gt 0) { 38 | # Some kind of error, figure out if its a bad password 39 | If ($Err.Exception.GetType().Name -eq "InvalidLogin") { 40 | Read-Host "Incorrect user name or password, hit any key to try again or to exit" 41 | } 42 | Else { 43 | # Something else went wrong, just display the text and exit 44 | $Err.Exception 45 | Break 46 | } 47 | } 48 | Else { 49 | Read-Host "User name and password are valid" 50 | Connect-VIServer $SourceVC -Credential $Cred 51 | } 52 | } 53 | Until ($Err.Count -eq 0) 54 | 55 | Do { 56 | # Loop until we get a valid userid/password and can connect, or some other kind of error occurs 57 | $Cred = Get-Credential -Message "Enter $destVC Credentials" 58 | $ConResult = Connect-VIServer -Server $destVC -Credential $Cred -ErrorAction SilentlyContinue -ErrorVariable Err 59 | If ($Err.Count -gt 0) { 60 | # Some kind of error, figure out if its a bad password 61 | If ($Err.Exception.GetType().Name -eq "InvalidLogin") { 62 | Read-Host "Incorrect user name or password, hit any key to try again or to exit" 63 | } 64 | Else { 65 | # Something else went wrong, just display the text and exit 66 | $Err.Exception 67 | Break 68 | } 69 | } 70 | Else { 71 | Read-Host "User name and password are valid" 72 | Connect-VIServer $destVC -Credential $Cred 73 | } 74 | } 75 | Until ($Err.Count -eq 0) 76 | 77 | 78 | 79 | $VM = Get-Cluster $sourceCluster -Server $sourceVC | Get-VM $vmname -Server $sourceVC -erroraction SilentlyContinue 80 | 81 | Describe -Name 'Testing vSphere Infrastructure' { 82 | Context -Name 'Checking vCenters for Cross-vCenter vMotion compatibility' { 83 | It -Name "Source and destination vCenter version are compatible with Cross vCenter vMotion (minimum 6.0)" { 84 | #($sourceVC.Version -ge [version]'6.0') -and ($destVC.Version -ge [version]'6.0') | Should Be $True 85 | } 86 | 87 | If ($sourceVC.Version -eq [version]'6.5') { 88 | It -Name "If source version equals 6.5, destination version should not be 6.0" { 89 | ($destVC.Version -eq [version]'6.0') | Should Be $false 90 | } 91 | } 92 | } 93 | 94 | Context -Name 'Testing Clusters translation table' { 95 | foreach ($cluster in $sourceCluster) { 96 | It "Source cluster $($SourceCluster) exists" { 97 | {Get-Cluster -Name $sourceCluster -Server $sourceVC} | Should Not Throw 98 | } 99 | It "Destination cluster $($DestCluster) exists" { 100 | {Get-Cluster -Name $DestCluster -Server $destVC} | Should Not Throw 101 | } 102 | } 103 | } 104 | 105 | Context -Name 'Testing VMHosts' { 106 | 107 | $sourceVMHosts = @() 108 | 109 | foreach ($cluster in $SourceCluster) { 110 | $sourceVMHosts += Get-Cluster -Name $sourceCluster -Server $sourceVC -ErrorAction SilentlyContinue | Get-VMHost -ErrorAction SilentlyContinue 111 | } 112 | 113 | $destinationVMHosts = @() 114 | 115 | foreach ($cluster in $DestCluster) { 116 | $destinationVMHosts += Get-Cluster -Name $destCluster -Server $destVC -ErrorAction SilentlyContinue | Get-VMHost -ErrorAction SilentlyContinue 117 | } 118 | 119 | It -Name "Source cluster contains VMhosts" { 120 | $sourceVMHosts.Count | Should BeGreaterThan 0 121 | } 122 | 123 | Foreach ($VMHost in $sourceVMHosts) { 124 | It -Name "Source VMHost $($VMHost.Name) version is compatible with Cross-vCenter vMotion (minimum 6.0)" { 125 | $VMHost.Version -ge [version]'6.0' | Should Be $True 126 | } 127 | } 128 | 129 | It -Name "Destination cluster contains VMhosts" { 130 | $destinationVMHosts.Count | Should BeGreaterThan 0 131 | } 132 | 133 | Foreach ($VMHost in $destinationVMHosts) { 134 | It -Name "Destination VMHost $($VMHost.Name) version is compatible with Cross vCenter vMotion (minimum 6.0)" { 135 | $VMHost.Version -ge [version]'6.0' | Should Be $True 136 | } 137 | } 138 | } 139 | 140 | Context -Name "Testing VMs" { 141 | It -Name "Found VM matching scope $($vmname)" { 142 | $VM.count | Should BeGreaterThan 0 143 | } 144 | } 145 | 146 | If ($PG) { 147 | Context -Name 'Testing Portgroups translation table' { 148 | Foreach ($portgroup in $PG) { 149 | 150 | $sourcePortgroup = Get-VirtualPortGroup -Name $sourcePG -Server $sourceVC -ErrorAction SilentlyContinue 151 | 152 | It -name "Source portgroup $($sourcePG) exists" { 153 | $sourcePortgroup.count | Should BeGreaterThan 0 154 | } 155 | 156 | $Destinationportgroup = Get-VirtualPortGroup -Name $destPG -Server $destVC -ErrorAction SilentlyContinue 157 | 158 | It -name "Destination portgroup $($destPG) exists" { 159 | $Destinationportgroup.count | Should BeGreaterThan 0 160 | } 161 | 162 | If ($sourcePortgroup.ExtensionData.Key -like 'dvportgroup-*') { 163 | It -name "If source portgroup is a vds, destination can't be a vss" { 164 | ($sourcePortgroup.ExtensionData.Key -like 'dvportgroup-*') -and ($Destinationportgroup.ExtensionData.Key -notlike 'dvportgroup-*') | Should Be $False 165 | } 166 | } 167 | } 168 | } 169 | } 170 | 171 | If ($DS) { 172 | Context -Name 'Testing Datastores translation table' { 173 | Foreach ($datastore in $DS) { 174 | It -name "Source datastore $($sourceDS) exists" { 175 | {Get-Datastore -Name $sourceDS -Server $sourceVC} | Should Not Throw 176 | } 177 | It -name "Destination datastore $($destDS) exists" { 178 | {Get-Datastore -Name $destDS -Server $destVC} | Should Not Throw 179 | } 180 | } 181 | } 182 | } 183 | } 184 | 185 | 186 | Write-host " Powering off $vm" -ForegroundColor Yellow 187 | Try{ 188 | $vmm = Get-VM -Name $vmName -ErrorAction Stop 189 | switch($vmm.PowerState){ 190 | 'poweredon' { 191 | Shutdown-VMGuest -VM $vm -Confirm:$false 192 | while($vmm.PowerState -eq 'PoweredOn'){ 193 | sleep 5 194 | 195 | $vmm = Get-VM -Name $vmName 196 | } 197 | } 198 | Default { 199 | Write-Host "VM '$($vmName)' is not powered on!" -ForegroundColor Yellow 200 | } 201 | } 202 | Write-Host "$($vmName) has shutdown. It should be ready for Migration to $destVC." -ForegroundColor Green 203 | } 204 | 205 | Catch{ 206 | 207 | Write-Host "VM '$($vmName)' not found!" -ForegroundColor Red 208 | 209 | } 210 | 211 | Sleep 10 212 | $vm = Get-VM $vmname -Server $sourceVC 213 | $Destination = Get-VMHost -Location $destCluster -Server $DestVC | Get-Random 214 | $NetworkAdapter = Get-NetworkAdapter -VM $vm -Server $sourceVC 215 | $VMPG = Get-VirtualPortGroup -VirtualSwitch $destSwitch -Name $DestPG -Server $destVC 216 | $DS = Get-Datastore -Name $destDS -Server $destVC 217 | 218 | Write-Host " Moving $vm from $sourceVC to $destVC. $vm will be in the $destCluster on host $destination. Please Stand By...." -ForegroundColor yellow 219 | 220 | Move-VM $vm -Destination $Destination -NetworkAdapter $NetworkAdapter -PortGroup $VMPG -Datastore $DS -Confirm:$false 221 | 222 | Sleep 5 223 | 224 | Write-Host " Powering on $vm and waiting for VM Tools to start" -ForegroundColor Green 225 | Start-VM $vmname -Server $DestVC 226 | 227 | do { 228 | $toolsStatus = (Get-VM $vmname | Get-View).Guest.ToolsStatus 229 | write-host $toolsStatus 230 | sleep 3 231 | } until ( $toolsStatus -eq ‘toolsOk’ ) 232 | 233 | #Update vmware tools 234 | Write-Host " Checking and upgrading VMware Tools and VM Copatibility if nesessary" -ForegroundColor Yellow 235 | Get-VM $vmname | % { get-view $_.id } |Where-Object {$_.Guest.ToolsVersionStatus -like "guestToolsNeedUpgrade"} |select name, @{Name=“ToolsVersion”; Expression={$_.config.tools.toolsversion}}, @{ Name=“ToolStatus”; Expression={$_.Guest.ToolsVersionStatus}}| Update-Tools -NoReboot -VM {$_.Name} -Verbose 236 | 237 | Write-Host " Rebooting $vmname after VM Compatibility Upgrade" 238 | Restart-VM -VM $vmname -Server $DestVC -Confirm:$false 239 | do { 240 | $toolsStatus = (Get-VM $vmname | Get-View).Guest.ToolsStatus 241 | write-host $toolsStatus 242 | sleep 3 243 | } until ( $toolsStatus -eq ‘toolsOk’ ) 244 | 245 | $StopWatch.Stop() 246 | #Calculating Migration Time 247 | $migrationTime = [math]::Round(($StopWatch.Elapsed).TotalMinutes ,2) 248 | 249 | Write-Host " $vm is ready to use. Migration is Complete" -ForegroundColor Green 250 | Write-Host " Total Migration time for $vmname was $migrationtime minutes" -ForegroundColor Cyan 251 | sleep 2 252 | Write-Host " Disconnecting from vCenters $sourceVC and $destVC" -ForegroundColor Yellow 253 | Disconnect-VIServer -Server * -Confirm:$false 254 | 255 | } 256 | -------------------------------------------------------------------------------- /ADinfo.ps1: -------------------------------------------------------------------------------- 1 | $Computers = (Get-ADComputer -Filter *).count 2 | $Workstations = (Get-ADComputer -LDAPFilter "(&(objectClass=Computer)(!operatingSystem=*server*))" -Searchbase (Get-ADDomain).distinguishedName).count 3 | $Servers = (Get-ADComputer -LDAPFilter "(&(objectClass=Computer)(operatingSystem=*server*))" -Searchbase (Get-ADDomain).distinguishedName).count 4 | $Users = (get-aduser -filter *).count 5 | $domain = Get-ADDomain |FT Forest 6 | $FSMO = netdom query FSMO 7 | $ADForest = (Get-ADForest).ForestMode 8 | $ADDomain = (Get-ADDomain).DomainMode 9 | $ADVer = Get-ADObject (Get-ADRootDSE).schemaNamingContext -property objectVersion | Select objectVersion 10 | $ADNUM = $ADVer -replace "@{objectVersion=","" -replace "}","" 11 | 12 | If ($ADNum -eq '88') {$srv = 'Windows Server 2019'} 13 | ElseIf ($ADNum -eq '87') {$srv = 'Windows Server 2016'} 14 | ElseIf ($ADNum -eq '69') {$srv = 'Windows Server 2012 R2'} 15 | ElseIf ($ADNum -eq '56') {$srv = 'Windows Server 2012'} 16 | ElseIf ($ADNum -eq '47') {$srv = 'Windows Server 2008 R2'} 17 | ElseIf ($ADNum -eq '44') {$srv = 'Windows Server 2008'} 18 | ElseIf ($ADNum -eq '31') {$srv = 'Windows Server 2003 R2'} 19 | ElseIf ($ADNum -eq '30') {$srv = 'Windows Server 2003'} 20 | 21 | 22 | 23 | Write-Host "For this Domain there are;" 24 | Write-Host "Computers = "$Computers -ForegroundColor Cyan 25 | Write-Host "Workstions = "$Workstations -ForegroundColor Cyan 26 | Write-Host "Servers = "$Servers -ForegroundColor Cyan 27 | Write-Host "Users = "$Users -ForegroundColor Cyan 28 | Write-host "" 29 | Write-host "Active Directory Info" -ForegroundColor Yellow 30 | Write-Host "Active Directory Forest Mode = "$ADForest -ForegroundColor Cyan 31 | Write-Host "Active Directory Domain Mode = "$ADDomain -ForegroundColor Cyan 32 | Write-Host "Active Directory Schema Version is $ADNum which corresponds to $Srv" -ForegroundColor Cyan 33 | Write-Host "" 34 | Write-Host "FSMO Role Owners" -ForegroundColor Cyan 35 | $FSMO 36 | 37 | Write-Host "Active Directory Health Check" -ForegroundColor Yellow 38 | Write-Host "" 39 | #####################################Get ALL DC Servers################################# 40 | $getForest = [system.directoryservices.activedirectory.Forest]::GetCurrentForest() 41 | 42 | $DCServers = $getForest.domains | ForEach-Object {$_.DomainControllers} | ForEach-Object {$_.Name} 43 | 44 | $timeout = "60" 45 | foreach ($DC in $DCServers){ 46 | $Identity = $DC 47 | ################Ping Test###### 48 | if ( Test-Connection -ComputerName $DC -Count 1 -ErrorAction SilentlyContinue ) { 49 | Write-Host $DC `t $DC `t Ping Success -ForegroundColor Green 50 | ##############Netlogon Service Status################ 51 | $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "Netlogon" -ErrorAction SilentlyContinue} -ArgumentList $DC 52 | wait-job $serviceStatus -timeout $timeout 53 | if($serviceStatus.state -like "Running") 54 | { 55 | Write-Host $DC `t Netlogon Service TimeOut -ForegroundColor Yellow 56 | stop-job $serviceStatus 57 | } 58 | else 59 | { 60 | $serviceStatus1 = Receive-job $serviceStatus 61 | if ($serviceStatus1.status -eq "Running") { 62 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green 63 | $svcName = $serviceStatus1.name 64 | $svcState = $serviceStatus1.status 65 | } 66 | else 67 | { 68 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red 69 | $svcName = $serviceStatus1.name 70 | $svcState = $serviceStatus1.status 71 | } 72 | } 73 | } 74 | ##############NTDS Service Status################ 75 | $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "NTDS" -ErrorAction SilentlyContinue} -ArgumentList $DC 76 | wait-job $serviceStatus -timeout $timeout 77 | if($serviceStatus.state -like "Running") 78 | { 79 | Write-Host $DC `t NTDS Service TimeOut -ForegroundColor Yellow 80 | stop-job $serviceStatus 81 | } 82 | else 83 | { 84 | $serviceStatus1 = Receive-job $serviceStatus 85 | if ($serviceStatus1.status -eq "Running") { 86 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green 87 | $svcName = $serviceStatus1.name 88 | $svcState = $serviceStatus1.status 89 | } 90 | else 91 | { 92 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red 93 | $svcName = $serviceStatus1.name 94 | $svcState = $serviceStatus1.status 95 | } 96 | } 97 | ##############DNS Service Status################ 98 | $serviceStatus = start-job -scriptblock {get-service -ComputerName $($args[0]) -Name "DNS" -ErrorAction SilentlyContinue} -ArgumentList $DC 99 | wait-job $serviceStatus -timeout $timeout 100 | if($serviceStatus.state -like "Running") 101 | { 102 | Write-Host $DC `t DNS Server Service TimeOut -ForegroundColor Yellow 103 | stop-job $serviceStatus 104 | } 105 | else 106 | { 107 | $serviceStatus1 = Receive-job $serviceStatus 108 | if ($serviceStatus1.status -eq "Running") { 109 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Green 110 | $svcName = $serviceStatus1.name 111 | $svcState = $serviceStatus1.status 112 | } 113 | else 114 | { 115 | Write-Host $DC `t $serviceStatus1.name `t $serviceStatus1.status -ForegroundColor Red 116 | $svcName = $serviceStatus1.name 117 | $svcState = $serviceStatus1.status 118 | } 119 | } 120 | ####################Netlogons status################## 121 | add-type -AssemblyName microsoft.visualbasic 122 | $cmp = "microsoft.visualbasic.strings" -as [type] 123 | $sysvol = start-job -scriptblock {dcdiag /test:netlogons /s:$($args[0])} -ArgumentList $DC 124 | wait-job $sysvol -timeout $timeout 125 | if($sysvol.state -like "Running") 126 | { 127 | Write-Host $DC `t Netlogons Test TimeOut -ForegroundColor Yellow 128 | stop-job $sysvol 129 | } 130 | else 131 | { 132 | $sysvol1 = Receive-job $sysvol 133 | if($cmp::instr($sysvol1, "passed test NetLogons")) 134 | { 135 | Write-Host $DC `t Netlogons Test passed -ForegroundColor Green 136 | } 137 | else 138 | { 139 | Write-Host $DC `t Netlogons Test Failed -ForegroundColor Red 140 | } 141 | } 142 | 143 | ####################Replications status################# 144 | add-type -AssemblyName microsoft.visualbasic 145 | $cmp = "microsoft.visualbasic.strings" -as [type] 146 | $sysvol = start-job -scriptblock {dcdiag /test:Replications /s:$($args[0])} -ArgumentList $DC 147 | wait-job $sysvol -timeout $timeout 148 | if($sysvol.state -like "Running") 149 | { 150 | Write-Host $DC `t Replications Test TimeOut -ForegroundColor Yellow 151 | stop-job $sysvol 152 | } 153 | else 154 | { 155 | $sysvol1 = Receive-job $sysvol 156 | if($cmp::instr($sysvol1, "passed test Replications")) 157 | { 158 | Write-Host $DC `t Replications Test passed -ForegroundColor Green 159 | } 160 | else 161 | { 162 | Write-Host $DC `t Replications Test Failed -ForegroundColor Red 163 | } 164 | } 165 | ####################Services status##################### 166 | add-type -AssemblyName microsoft.visualbasic 167 | $cmp = "microsoft.visualbasic.strings" -as [type] 168 | $sysvol = start-job -scriptblock {dcdiag /test:Services /s:$($args[0])} -ArgumentList $DC 169 | wait-job $sysvol -timeout $timeout 170 | if($sysvol.state -like "Running") 171 | { 172 | Write-Host $DC `t Services Test TimeOut -ForegroundColor Yellow 173 | stop-job $sysvol 174 | } 175 | else 176 | { 177 | $sysvol1 = Receive-job $sysvol 178 | if($cmp::instr($sysvol1, "passed test Services")) 179 | { 180 | Write-Host $DC `t Services Test passed -ForegroundColor Green 181 | } 182 | else 183 | { 184 | Write-Host $DC `t Services Test Failed -ForegroundColor Red 185 | } 186 | } 187 | ####################Advertising status################## 188 | add-type -AssemblyName microsoft.visualbasic 189 | $cmp = "microsoft.visualbasic.strings" -as [type] 190 | $sysvol = start-job -scriptblock {dcdiag /test:Advertising /s:$($args[0])} -ArgumentList $DC 191 | wait-job $sysvol -timeout $timeout 192 | if($sysvol.state -like "Running") 193 | { 194 | Write-Host $DC `t Advertising Test TimeOut -ForegroundColor Yellow 195 | stop-job $sysvol 196 | } 197 | else 198 | { 199 | $sysvol1 = Receive-job $sysvol 200 | if($cmp::instr($sysvol1, "passed test Advertising")) 201 | { 202 | Write-Host $DC `t Advertising Test passed -ForegroundColor Green 203 | } 204 | else 205 | { 206 | Write-Host $DC `t Advertising Test Failed -ForegroundColor Red 207 | } 208 | } 209 | ####################FSMOCheck status################## 210 | add-type -AssemblyName microsoft.visualbasic 211 | $cmp = "microsoft.visualbasic.strings" -as [type] 212 | $sysvol = start-job -scriptblock {dcdiag /test:FSMOCheck /s:$($args[0])} -ArgumentList $DC 213 | wait-job $sysvol -timeout $timeout 214 | if($sysvol.state -like "Running") 215 | { 216 | Write-Host $DC `t FSMOCheck Test TimeOut -ForegroundColor Yellow 217 | stop-job $sysvol 218 | } 219 | else 220 | { 221 | $sysvol1 = Receive-job $sysvol 222 | if($cmp::instr($sysvol1, "passed test FsmoCheck")) 223 | { 224 | Write-Host $DC `t FSMOCheck Test passed -ForegroundColor Green 225 | } 226 | else 227 | { 228 | Write-Host $DC `t FSMOCheck Test Failed -ForegroundColor Red 229 | } 230 | } 231 | Write-Host "" 232 | } 233 | -------------------------------------------------------------------------------- /FormMove-CrossVC.ps1: -------------------------------------------------------------------------------- 1 | $inputXML = @" 2 | 3 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |