Skip to content

Commit f4e6281

Browse files
committed
Added credential parameter. Implemented remoting
1 parent d444c3e commit f4e6281

1 file changed

Lines changed: 35 additions & 9 deletions

File tree

internal/functions/Test-PSDCHyperVEnabled.ps1

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
.PARAMETER HostName
1111
Hostname to check. The default is the current hostname
1212
13+
.PARAMETER Credential
14+
Allows you to login to servers using Windows Auth/Integrated/Trusted. To use:
15+
16+
$scred = Get-Credential, then pass $scred object to the -Credential parameter.
17+
1318
.PARAMETER EnableException
1419
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message.
1520
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting.
@@ -47,30 +52,51 @@
4752
[OutputType([bool])]
4853

4954
param(
50-
[string]$HostName = $env:COMPUTERNAME.
55+
[string]$HostName = $env:COMPUTERNAME,
56+
[System.Management.Automation.PSCredential]$Credential,
5157
[switch]$EnableException
5258
)
5359

54-
$osDetails = Get-CimInstance Win32_OperatingSystem -ComputerName $HostName | Select-Object Caption, Description, Name, OSType, Version
60+
$computer = [PSFComputer]$HostName
61+
62+
if ($computer.IsLocalhost) {
63+
$osDetails = Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Description, Name, OSType, Version
64+
}
65+
else {
66+
$command = [scriptblock]::Create("Get-CimInstance Win32_OperatingSystem | Select-Object Caption, Description, Name, OSType, Version")
67+
68+
$osDetails = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
69+
}
5570

5671
# Check if the Hyper-V feature is enabled
5772
if ($osDetails.Caption -like '*Windows 10*') {
58-
$feature = Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-All' -Online
59-
if ($feature.State -eq "Enabled") {
60-
return $true
73+
if ($computer.IsLocalhost) {
74+
$feature = Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-All' -Online
6175
}
6276
else{
77+
$command = [scriptblock]::Create("Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-All' -Online")
78+
$feature = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
79+
}
80+
81+
if($feature.State -ne "Enabled"){
6382
return $false
6483
}
84+
else{
85+
return $true
86+
}
87+
6588
}
6689
elseif ($osDetails.Caption -like '*Windows Server*') {
67-
$feature = Get-WindowsFeature -Name 'Hyper-V'
68-
if ($feature.Installed) {
69-
return $true
90+
if ($computer.IsLocalhost) {
91+
$feature = Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V-All' -Online
7092
}
7193
else{
72-
return $false
94+
$command = [scriptblock]::Create("Get-WindowsFeature -Name 'Hyper-V'")
95+
$feature = Invoke-PSFCommand -ComputerName $computer -ScriptBlock $command -Credential $Credential
7396
}
97+
98+
return $feature.Installed
7499
}
75100

101+
76102
}

0 commit comments

Comments
 (0)