Merging dev with master #7
@ -6,12 +6,6 @@
|
||||
|
||||
$DebugPreference = "Continue"
|
||||
$ErrorActionPreference = "Stop"
|
||||
$SCRIPT_PATH=$PSScriptRoot
|
||||
#$HYPERV_FILE = "$SCRIPT_PATH/hyperv_list.txt"
|
||||
$SCVMM_FILE = "$SCRIPT_PATH/hyperv_list.txt"
|
||||
$VSPHERE_FILE = "$SCRIPT_PATH/vsphere_list.txt"
|
||||
$HOSTS_FILE = "$SCRIPT_PATH/hosts.txt"
|
||||
|
||||
|
||||
### Disable Participation messages
|
||||
#Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -Confirm:$false
|
||||
@ -225,12 +219,11 @@ class vSphereServer: VirtualizationServer
|
||||
__load_hosts()
|
||||
{
|
||||
Connect-VIServer -Server $this.url
|
||||
$list = VMware.VimAutomation.Core\Get-VM
|
||||
$list = VMware.VimAutomation.Core\Get-VM -Location $this.url
|
||||
$this.__host_list=$list
|
||||
}
|
||||
[Boolean] __check_login()
|
||||
{
|
||||
|
||||
Connect-VIServer -Server $this.url
|
||||
$result=$?
|
||||
# Disconnect-VIServer -Server $this.url
|
||||
@ -239,12 +232,12 @@ class vSphereServer: VirtualizationServer
|
||||
|
||||
}
|
||||
# This remains unused??
|
||||
class VirtualizerManager
|
||||
{
|
||||
load_hyperv_from_file(){}
|
||||
load_scvmm_from_file(){}
|
||||
load_vcenter_from_file(){}
|
||||
}
|
||||
#class VirtualizerManager
|
||||
#{
|
||||
# load_hyperv_from_file(){}
|
||||
# load_scvmm_from_file(){}
|
||||
# load_vcenter_from_file(){}
|
||||
#}
|
||||
|
||||
class VirtualizerAssistant
|
||||
{
|
||||
@ -343,54 +336,120 @@ class VirtualizerAssistant
|
||||
# }
|
||||
}
|
||||
|
||||
function Get-Hosts-From-File($filepath)
|
||||
{
|
||||
## In a future use a yaml as a .conf (with the hyperv and vmware listed)
|
||||
$file_content = Get-Content "$filepath"
|
||||
$splitted_file_content = $file_content.Split()
|
||||
$host_array=@()
|
||||
foreach ($hostname in $splitted_file_content)
|
||||
{
|
||||
if ($hostname)
|
||||
{
|
||||
$host_array+=$hostname
|
||||
|
||||
#Used to store the config
|
||||
class Config{
|
||||
$_SCRIPT_PATH=$PSScriptRoot
|
||||
$_HYPERV_FILE = [String]::Format("{0}/hyperv_list.txt",$this.SCRIPT_PATH)
|
||||
$_SCVMM_FILE = [String]::Format("{0}/scvmm_list.txt",$this.SCRIPT_PATH)
|
||||
$_VSPHERE_FILE = [String]::Format("{0}/vsphere_list.txt",$this.SCRIPT_PATH)
|
||||
$_HOSTS_FILE = [String]::Format("{0}/hosts.txt",$this.SCRIPT_PATH)
|
||||
Load_Hyperv($manager) {
|
||||
$hyperv_urls = Get-Hosts-From-File($this._HYPERV_FILE)
|
||||
foreach ($url in $hyperv_urls) {
|
||||
$manager.append_session([HypervisorServer], $url)
|
||||
}
|
||||
}
|
||||
return $host_array
|
||||
|
||||
Load_Scvmm([VirtualizerAssistant] $manager) {
|
||||
$hyperv_urls = Get-Hosts-From-File($this._SCVMM_FILE)
|
||||
foreach ($url in $hyperv_urls) {
|
||||
$manager.append_session([SystemCenterVirtualMachineManager], $url)
|
||||
}
|
||||
}
|
||||
Load_Vsphere($manager) {
|
||||
$vsphere_urls = Get-Hosts-From-File($this._VSPHERE_FILE)
|
||||
foreach ($url in $vsphere_urls) {
|
||||
$manager.append_session([vSphereServer], $url)
|
||||
}
|
||||
}
|
||||
|
||||
[String[]]GetHostsFromFile($filepath)
|
||||
{
|
||||
## In a future use a yaml as a .conf (with the hyperv and vmware listed)
|
||||
$file_content = Get-Content "$filepath"
|
||||
$splitted_file_content = $file_content.Split()
|
||||
$host_array=@()
|
||||
foreach ($hostname in $splitted_file_content)
|
||||
{
|
||||
if ($hostname)
|
||||
{
|
||||
$host_array+=$hostname
|
||||
}
|
||||
}
|
||||
return $host_array
|
||||
}
|
||||
|
||||
|
||||
# Load_All_Servers($x){
|
||||
# $this.G
|
||||
# }
|
||||
# Load_All{
|
||||
#
|
||||
# }
|
||||
}
|
||||
|
||||
|
||||
class Menu{
|
||||
|
||||
$exit=$false
|
||||
[VirtualizerAssistant]$Assistant
|
||||
[Config]$Config
|
||||
|
||||
print_menu(){
|
||||
Write-Host "Select an option an option:"
|
||||
Write-Host @"
|
||||
`t- 0 Attempt to log in into the servers (authenticates with the current session)
|
||||
`t- 1 Load VMs
|
||||
`t- 2 Find Hosts
|
||||
`t- 3 Disconnect from all servers and reload server list content
|
||||
`t- 4 Reload VM file list content
|
||||
`t- -1 Exit
|
||||
"@
|
||||
}
|
||||
|
||||
select_menu(){
|
||||
$uinput=Read-Host "Please enter your option"
|
||||
switch ($uinput) {
|
||||
-1 {
|
||||
$this.Quit()
|
||||
}
|
||||
0 {
|
||||
|
||||
}
|
||||
Default {
|
||||
Write-Host "Error, try again"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu(){
|
||||
while (!$this.exit){
|
||||
$this.print_menu()
|
||||
$this.select_menu()
|
||||
}
|
||||
}
|
||||
Quit(){
|
||||
$this.exit=$true
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
# Advanced params?
|
||||
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_parameters?view=powershell-7.2
|
||||
function load_hyperv($manager) {
|
||||
$hyperv_urls = Get-Hosts-From-File($HYPERV_FILE)
|
||||
foreach ($url in $hyperv_urls) {
|
||||
$manager.append_session([HypervisorServer], $url)
|
||||
}
|
||||
}
|
||||
|
||||
function load_scvmm([VirtualizerAssistant] $manager) {
|
||||
$hyperv_urls = Get-Hosts-From-File($SCVMM_FILE)
|
||||
foreach ($url in $hyperv_urls) {
|
||||
$manager.append_session([SystemCenterVirtualMachineManager], $url)
|
||||
}
|
||||
}
|
||||
function load_vsphere($manager) {
|
||||
$vsphere_urls = Get-Hosts-From-File($VSPHERE_FILE)
|
||||
foreach ($url in $vsphere_urls) {
|
||||
$manager.append_session([vSphereServer], $url)
|
||||
}
|
||||
}
|
||||
#
|
||||
#function Test_VM{
|
||||
# $_____url=$_____url
|
||||
# $manager = [VirtualizerAssistant]::new()
|
||||
# $manager.append_session([SystemCenterVirtualMachineManager], $_____url)
|
||||
# $manager.__connected_servers[0].get_host_list()[0]
|
||||
#}
|
||||
|
||||
|
||||
function Test_VM{
|
||||
$_____url=$_____url
|
||||
$manager = [VirtualizerAssistant]::new()
|
||||
$manager.append_session([SystemCenterVirtualMachineManager], $_____url)
|
||||
$manager.__connected_servers[0].get_host_list()[0]
|
||||
}
|
||||
|
||||
function Main{
|
||||
$manager = [VirtualizerAssistant]::new()
|
||||
load_vsphere($manager)
|
||||
$manager.load_hosts()
|
||||
$vmhosts = Get-Hosts-From-File($HOSTS_FILE)
|
||||
|
Loading…
x
Reference in New Issue
Block a user