Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase Performance of Test-IsNanoServer #652

Closed
PlagueHO opened this issue Dec 27, 2019 · 5 comments · Fixed by #693
Closed

Increase Performance of Test-IsNanoServer #652

PlagueHO opened this issue Dec 27, 2019 · 5 comments · Fixed by #693
Assignees
Labels
enhancement The issue is an enhancement request. in progress The issue is being actively worked on by someone.

Comments

@PlagueHO
Copy link
Member

The cmdlet Test-IsNanoServer is used by many of the resources. This cmdlet uses Get-ComputerInfo to determine if the machine is Nano server:

function Test-IsNanoServer
{
    [OutputType([System.Boolean])]
    [CmdletBinding()]
    param ()

    $isNanoServer = $false

    if (Test-CommandExists -Name 'Get-ComputerInfo')
    {
        $computerInfo = Get-ComputerInfo

        $computerIsServer = 'Server' -ieq $computerInfo.OsProductType

        if ($computerIsServer)
        {
            $isNanoServer = 'NanoServer' -ieq $computerInfo.OsServerLevel
        }
    }

    return $isNanoServer
}

However, Get-ComputerInfo is very slow, taking over 2 seconds on average to execute.

This causes the resources to run slow and increases overall test time significantly.

We should find a better way to detect if a machine is Nano Server.

@PlagueHO PlagueHO added enhancement The issue is an enhancement request. help wanted The issue is up for grabs for anyone in the community. labels Dec 27, 2019
@PlagueHO
Copy link
Member Author

One possible way of increasing performance is to instead use a CIM command to pull the Win32_OperatingSystem class (https://docs.microsoft.com/en-us/windows/win32/cimwin32prov/win32-operatingsystem) and use the OperatingSystemSKU property:

$productDatacenterNanoServer = 143
$productStandardNanoServer = 144

function Test-IsNanoServer
{
    [OutputType([System.Boolean])]
    [CmdletBinding()]
    param ()

    $operatingSystemSKU = (Get-CimInstance -ClassName Win32_OperatingSystem).OperatingSystemSKU

    return ($operatingSystemSKU -in ($productDatacenterNanoServer,$productStandardNanoServer))
}

Is there anyone who knows a reason why this would not be a viable alternative? @gaelcolas , @johlju

@johlju
Copy link
Member

johlju commented Dec 27, 2019

If the class exist in a Nano server then I don't see an issue using it.

@HansOMartinsen
Copy link

The class exists on Nanaoserver. Ref: https://docs.microsoft.com/en-us/previous-versions/windows/desktop/legacy/mt588480(v=vs.85)

Any reason not to go ahead and implement this as in "Add Test-IsNanoServer dsccommunity/DscResource.Common#9"?

@PlagueHO
Copy link
Member Author

PlagueHO commented Jun 5, 2020

No reason at all :) Please go ahead @HansOMartinsen !

@PlagueHO
Copy link
Member Author

PlagueHO commented Jul 5, 2020

Implementing #685 will resolve this issue. I'll be planning this over the next week.

@PlagueHO PlagueHO removed the help wanted The issue is up for grabs for anyone in the community. label Jul 5, 2020
@PlagueHO PlagueHO self-assigned this Jul 5, 2020
@PlagueHO PlagueHO added the in progress The issue is being actively worked on by someone. label Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is an enhancement request. in progress The issue is being actively worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants