From 75e96580d1a75f5c2720fd0a040664606b4516d6 Mon Sep 17 00:00:00 2001 From: ofilter Date: Thu, 7 Apr 2022 20:54:52 +0200 Subject: [PATCH] Working with minor errors. --- Testing/sirius.ps1 | 59 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/Testing/sirius.ps1 b/Testing/sirius.ps1 index 791a96d..8933919 100644 --- a/Testing/sirius.ps1 +++ b/Testing/sirius.ps1 @@ -39,17 +39,35 @@ class VirtualizationServer { [Array] get_host_list(){ return $this.__host_list } + [Boolean] __check_login(){ + $type=$this.GetType().BaseType + Write-Warning "Check_login not implemented in type $type" + return $false + } + [Boolean] check_login(){ + Invoke-Command -ComputerName $this.url { $true } + return $this.check_login() + } } class SystemCenterVirtualMachineManager: VirtualizationServer { __load_hosts(){ Get-SCVMMServer -ComputerName $this.url $list = Get-SCVirtualMachine $this.__host_list=$list - [string]::Format("Loaded VM from {0}",$this.url) | Write-Debug - + [string]::Format("Loaded {0} VM from {1}",$list.Lenght,$this.url) | Write-Debug + } + [Boolean] __check_login($url){ + $result=Invoke-Command -ComputerName $this.url { $true } + $status_message = "OK" + return $result } } class HypervisorServer: VirtualizationServer{ + [Boolean] __log_in($url){ + $result=Invoke-Command -ComputerName $this.url { $true } + $status_message = "OK" + return $result + } # [Boolean] _FindHost ($vname) { # $result=$false # try @@ -77,13 +95,14 @@ class VirtualizerManager{ $result=$false try { $result=Invoke-Command -ComputerName $url { $true } - $status_message = "OK" } catch [System.Management.Automation.Remoting.PSRemotingTransportException] { - $status_message = Format("Error '{0}'",$_.Exception.GetType().fullname) + Write-Host $url + Write-Error [String]::Format("Failed to log in to URL: {0}",$url) + Write-Debug [String]::Format("`tError {0}",$Error[0]) } finally { - $message = [string]::Format(">> [{0}] {1}",$url,$status_message) + $message = [string]::Format(">> Status {0}",@("NotOK","OK")) Write-Debug $message } return $result @@ -139,7 +158,7 @@ class VirtualizerManager{ { $server_location = $entry_from_dict.Name $vm = $entry_from_dict.Value - [String]::Format("`t`tFound in '{0}'", $server_location) | Write-Host + [String]::Format("`t`tFound in {0}", $server_location) | Write-Host } Write-Host "`-----------`n" } @@ -185,15 +204,15 @@ function Get-Hosts-From-File($filepath) # 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_url = Get-Hosts-From-File($HYPERV_FILE) - foreach ($url in $hyperv_url) { + $hyperv_urls = Get-Hosts-From-File($HYPERV_FILE) + foreach ($url in $hyperv_urls) { $manager.append_session([HypervisorServer], $url) } } function load_scvmm($manager) { - $hyperv_url = Get-Hosts-From-File($SCVMM_FILE) - foreach ($url in $hyperv_url) { + $hyperv_urls = Get-Hosts-From-File($SCVMM_FILE) + foreach ($url in $hyperv_urls) { $manager.append_session([SystemCenterVirtualMachineManager], $url) } } @@ -205,13 +224,23 @@ function Main{ $vmhosts = Get-Hosts-From-File($HOSTS_FILE) $manager.find_hosts($vmhosts) } - -function Test_VCSMM{ +function Test_Manager_Login{ $manager = [VirtualizerManager]::new() load_scvmm($manager) - [VirtualizationServer]$x=$manager.__connected_servers[0] - $x.load_hosts() - $x.get_host_list() + #$manager.load_hosts() +} + +function Test_Auth_SCVM{ + $hyperv_urls = Get-Hosts-From-File($SCVMM_FILE) + $hyperv = [SystemCenterVirtualMachineManager]::new() + $hyperv.url = $hyperv_urls[0] + $hyperv.check_login() +} + +function Test_Auth_SCVM2{ + $name="asdasd" + Invoke-Command -ComputerName $name { $true } } Main +