AutomatedLab / AutomatedLab.Common

PowerShell module for daily administrative tasks and general helper functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WARNING: Module AutomatedLab.Common requires PS Version 5.1

constantinhager opened this issue · comments

I checked the psd1 - File. It says:
PowerShellVersion = '5.1'
but
CompatiblePSEditions = @('Desktop','Core')

Is it PowerShell 7 compatible?

Because if I deploy a Lab with PowerShell 7 i get the warning that is mentioned in the title

Nope, fully compatible. The warning you have seen is likely from here:

Write-Warning -Message "Module $($Local:Module.Name) requires PS Version $($Local:Module.PowerShellVersion). We only found $($sessionVersion) on $($s.ComputerName). Skipping."

That reminds me: I need to add an issue template here to capture necessary information for troubleshooting...

That would be great. Should that line be removed

Well, no, of course not. Just because it is inconvenient doesn't diminish its purpose: Send-ModuleToPSSession is not helpful, if the module being sent cannot be imported. Thus, a warning is generated and the module is skipped.

Can you please provide all the required steps to reproduce this issue? I am unable to reproduce the issue, it works fine for me. Unless, that is, I deploy an old version of Windows Server, say 2012 R2, in which case the module is getting skipped as intended, as it is not compatible with PSv4 in this case.

AutomatedLab sends AutomatedLab.Common to all nodes in a lab since we rely on some of its functionality.

What I will do is to check if the Force parameter is present and if it is, send the module regardless of if it is supported - even if it does not make sense to me, personally.

I need to check where in AutomatedLab we do rely on this module. At some point, @raandree added better exception handling in Install-LabSoftwarePackage, which was the main reason we send the module to the sessions. Instead of the built-in type Win32Exception we use our own for a reason I cannot remember.

In general, I do not envision backporting this module to some ancient PowerShell versions. We use too many features of modern PowerShell editions and would essentially have to rip out functionality. Also, 5.1 has been out for so long now that there is no good reason to use any older version.

I will provide a Lab for you to test and post the PS 5.1 and PS 7 output.

The error I found is my fault. I used the following lab in PS 7

Name                           Value
----                           -----
PSVersion                      7.3.1
PSEdition                      Core
GitCommitId                    7.3.1
OS                             Microsoft Windows 10.0.22621
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

AL Version in PS 7:

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.46.0                AutomatedLab                        {Add-LabAzureSubscription, Add-LabCertificate, Add-LabVMUserRight, Add-LabVMWareSettings…}
Script     2.3.0                 AutomatedLab.Common                 {Add-AccountPrivilege, Add-CATemplateStandardPermission, Add-Certificate2, Add-FunctionToPSSession…}
Script     0.0                   AutomatedLab.init
Script     5.46.0                AutomatedLabDefinition              {Add-LabAzureAppServicePlanDefinition, Add-LabAzureWebAppDefinition, Add-LabDiskDefinition, Add-LabDomainDefinition…}
Script     5.46.0                AutomatedLabNotifications           Send-ALNotification
Script     5.46.0                AutomatedLabTest                    {Import-LabTestResult, Invoke-LabPester, New-LabPesterTest, Test-LabDeployment}
Script     5.46.0                AutomatedLabUnattended              {Add-UnattendedNetworkAdapter, Add-UnattendedRenameNetworkAdapters, Add-UnattendedSynchronousCommand, Export-UnattendedFi…
Script     5.46.0                AutomatedLabWorker                  {Add-LWAzureLoadBalancedPort, Add-LWVMVHDX, Checkpoint-LWAzureVM, Checkpoint-LWHypervVM…}
$LabName = 'PowerShellCourse'

New-LabDefinition -Name $LabName -DefaultVirtualizationEngine HyperV

$Parameters = @{
    Name             = 'Default Switch'
    HyperVProperties = @{
        SwitchType  = 'External'
        AdapterName = 'Ethernet'
    }
}
Add-LabVirtualNetworkDefinition @Parameters

Add-LabDomainDefinition -Name 'pscourse.net' -AdminUser install -AdminPassword "Start.12345!"
Set-LabInstallationCredential -Username Install -Password "Start.12345!"

$PSDefaultParameterValues = @{
    'Add-LabMachineDefinition:ToolsPath'       = "$labSources\Tools"
    'Add-LabMachineDefinition:OperatingSystem' = 'Windows Server 2022 Datacenter (Desktop Experience)'
    'Add-LabMachineDefinition:Memory'          = 2048MB
}

$roles = Get-LabMachineRoleDefinition -Role RootDC
Add-LabMachineDefinition -Name DC1 -Roles $roles -DomainName 'pscourse.net' -Network 'Default Switch'
Add-LabMachineDefinition -Name MemberServer -DomainName 'pscourse.net' -Network 'Default Switch'

Install-Lab

Install-LabSoftwarePackage -Path "$labSources\Tools\VSCodeSetup" -ComputerName MemberServer -CommandLine "/silent /mergetasks='!runcode,addcontextmenufiles,addcontextmenufolders,associatewithfiles,addtopath'"

Show-LabDeploymentSummary -Detailed

Output of this is:

17:27:24|00:00:00|00:00:00.000| Initialization
17:27:24|00:00:00|00:00:00.121| - Host operating system version: 'Microsoft Windows 11 Pro, 10.0.22621.0'
17:27:24|00:00:00|00:00:00.122| - Creating new lab definition with name 'PowerShellCourse'
17:27:24|00:00:00|00:00:00.126| - Location of lab definition files will be 'C:\ProgramData\AutomatedLab/Labs/PowerShellCourse'
17:27:25|00:00:00|00:00:00.825| - Location of LabSources folder is 'E:\LabSources'
17:27:25|00:00:00|00:00:00.000| - Auto-adding ISO files
17:27:25|00:00:00|00:00:00.045|   - Added 'E:\LabSources\ISOs\en_sql_server_2008_r2_enterprise_x86_x64_ia64_dvd_520517.iso'
17:27:25|00:00:00|00:00:00.048|   - Added 'E:\LabSources\ISOs\en_sql_server_2012_enterprise_edition_with_service_pack_4_x64_dvd_11444956.iso'
17:27:25|00:00:00|00:00:00.050|   - Added 'E:\LabSources\ISOs\en_sql_server_2014_enterprise_edition_with_service_pack_3_x64_dvd_2f7d5d72.iso'
17:27:25|00:00:00|00:00:00.052|   - Added 'E:\LabSources\ISOs\en_sql_server_2016_enterprise_with_service_pack_2_x64_dvd_12124051.iso'
17:27:25|00:00:00|00:00:00.055|   - Added 'E:\LabSources\ISOs\en-us_windows_server_2022_updated_aug_2022_x64_dvd_8b65e57f.iso'
17:27:25|00:00:00|00:00:00.057|   - Done
17:27:25|00:00:01|00:00:00.000| - Adding Hyper-V machine definition 'DC1'         (Roles: RootDC)
17:27:26|00:00:02|00:00:01.403|   - Done
17:27:27|00:00:02|00:00:00.000| - Adding Hyper-V machine definition 'MemberServer'
17:27:27|00:00:02|00:00:00.392|   - Done
17:27:27|00:00:03|00:00:00.740| Estimated (additional) local drive space needed for all machines: 4 GB
17:27:28|00:00:03|00:00:01.135| Location of Hyper-V machines will be 'E:\AutomatedLab-VMs'
17:27:28|00:00:03|00:00:01.147| Done
17:27:28|00:00:03|00:00:00.000| Validating lab definition
17:27:28|00:00:04|00:00:00.543| - Could not invoke validator AutomatedLab.DomainMemberDns
17:27:34|00:00:09|00:00:05.843| - Issue: 'Default Switch'. Cause: There is already a virtual switch with the same name but a different switch type
17:27:34|00:00:09|00:00:05.847| - Success
17:27:34|00:00:09|00:00:05.915| Lab 'PowerShellCourse' hosted on 'HyperV' imported with 2 machines
17:27:34|00:00:10|00:00:00.000| Creating virtual networks
17:27:34|00:00:10|00:00:00.000| - Creating Hyper-V virtual network 'Default Switch'
17:27:34|00:00:10|00:00:00.008|   - The network switch 'Default Switch' already exists, no changes will be made to configuration
17:27:34|00:00:10|00:00:00.014|   - Done
17:27:34|00:00:10|00:00:00.019| - done
17:27:34|00:00:10|00:00:00.000| - Creating base images
17:27:34|00:00:10|00:00:00.012|   - All base images were created previously
17:27:36|00:00:11|00:00:01.306|   - Done
17:27:36|00:00:11|00:00:01.309| - done
17:27:36|00:00:11|00:00:00.000| - Creating Additional Disks
17:27:37|00:00:13|00:00:01.584|   - Done
17:27:37|00:00:13|00:00:00.000| - Creating VMs
17:27:37|00:00:13|00:00:00.000|   - Waiting for all machines to finish installing
17:27:37|00:00:13|00:00:00.000|     - Creating HyperV machine 'DC1'.....
17:28:34|00:01:09|00:00:56.280|       - ....Done
17:30:48|00:03:24|00:00:00.000|     - Creating HyperV machine 'MemberServer'.....
17:30:53|00:03:29|00:00:05.209|       - Done
17:30:53|00:03:29|00:00:05.211|     - Done
17:30:54|00:03:29|00:00:05.563|   - Done
17:30:54|00:03:29|00:00:00.000| - Installing Root Domain Controllers
17:30:54|00:03:29|00:00:00.035|   - Machines with RootDC role to be installed: 'DC1'
17:30:54|00:03:29|00:00:00.057|   - Waiting for machines to start up..
17:31:04|00:03:39|00:00:09.794|   - Waiting for Root Domain Controllers to complete installation of Active Directory and restart....done
17:33:54|00:06:29|00:03:00.024|   - Root Domain Controllers have now restarted. Waiting for Active Directory to start up.........
ConvertTo-Mask: Cannot validate argument on parameter 'MaskLength'. The argument is null, empty, or an element of the argument collection contains a null value. Supply a collection that does not contain any
null values and then try the command again.
Get-NetworkSummary: Cannot bind argument to parameter 'IPAddress' because it is an empty string.
17:35:24|00:08:00|00:04:30.526|   - Done
17:35:25|00:08:00|00:00:00.000| - Starting remaining machines
17:35:25|00:08:00|00:00:00.007|   - Waiting for machines to start up....................................................................................................
17:54:10|00:26:46|00:18:45.418|   - Done
17:54:10|00:26:46|00:00:00.000| - Installing RDS certificates of lab machines
17:54:11|00:26:47|00:00:00.976|   - ..
17:54:14|00:26:49|00:00:03.697|   - Done
17:54:14|00:26:49|00:00:00.000| - Adding lab machines to C:\Users\const/.ssh/known_hosts
17:54:24|00:27:00|00:00:10.436|   - Done

I get the following output in PS 5.1

Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

AL Version in PS 5.1:

Script     5.46.0     AutomatedLab                        {Add-LabAzureSubscription, Add-LabCertificate, Add-LabVMUserRight, Add-LabVMWareSettings...}
Script     2.2.247    AutomatedLab.Common                 {Add-AccountPrivilege, Add-CATemplateStandardPermission, Add-Certificate2, Add-FunctionToPSSession...}
Script     0.0        AutomatedLab.init
Script     5.46.0     AutomatedLabDefinition              {Add-LabAzureAppServicePlanDefinition, Add-LabAzureWebAppDefinition, Add-LabDiskDefinition, Add-LabDomainDefinition...}
Script     5.46.0     AutomatedLabNotifications           Send-ALNotification
Script     5.46.0     AutomatedLabTest                    {Import-LabTestResult, Invoke-LabPester, New-LabPesterTest, Test-LabDeployment}
Script     5.46.0     AutomatedLabUnattended              {Add-UnattendedNetworkAdapter, Add-UnattendedRenameNetworkAdapters, Add-UnattendedSynchronousCommand, Export-UnattendedFile...}
Script     5.46.0     AutomatedLabWorker                  {Add-LWAzureLoadBalancedPort, Add-LWVMVHDX, Checkpoint-LWAzureVM, Checkpoint-LWHypervVM...}

Output of Lab in PS 5.1:

i1
i2

The issue with this is that the MemberServer cannot find the domain because of a dns issue because the DefaultSwitch is used. What is the meaning of the two errors that appear with ConvertTo-Maskand and Get-NetworkSummary. Is this the fault of my misconfigured lab?