From 4b1f040694cdae78cc51f51e18125268588c1f7f Mon Sep 17 00:00:00 2001 From: Nik Charlebois Date: Thu, 1 Aug 2024 12:39:58 -0400 Subject: [PATCH] Revert "Improve PowerShell 7 support" --- CHANGELOG.md | 3 - .../Dependencies/Manifest.psd1 | 7 -- .../Modules/M365DSCReport.psm1 | 21 +---- .../Microsoft365DSC/Modules/M365DSCUtil.psm1 | 78 ++----------------- Tests/TestHarness.psm1 | 1 - .../get-started/powershell7-support.md | 6 +- 6 files changed, 11 insertions(+), 105 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4ecca8543..4146d32157 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,9 +20,6 @@ * M365DSCReport * Update key properties for delta report in `AADGroup` resource. FIXES [#4921](https://github.com/microsoft/Microsoft365DSC/issues/4921) - * Improve PowerShell Core support across the DSC resources. - FIXES [#4911](https://github.com/microsoft/Microsoft365DSC/issues/4911) - # 1.24.724.1 diff --git a/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 b/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 index b92a99656b..ffb61d0613 100644 --- a/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 +++ b/Modules/Microsoft365DSC/Dependencies/Manifest.psd1 @@ -96,13 +96,6 @@ ModuleName = 'PnP.PowerShell' RequiredVersion = '1.12.0' }, - @{ - ModuleName = 'PSDesiredStateConfiguration' - RequiredVersion = '2.0.7' - PowerShellCore = $true - ExplicitLoading = $true - Prefix = 'Pwsh' - }, @{ ModuleName = 'ReverseDSC' RequiredVersion = '2.0.0.20' diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 index 104aa83797..bf7ce34d56 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReport.psm1 @@ -419,21 +419,12 @@ function Get-Base64EncodedImage { $mimeType = "image/jpeg" } - if($icon.Extension.endsWith("png")) { $mimeType = "image/png" } - if ($PSVersionTable.PSEdition -eq 'Core') - { - $base64EncodedImage = [System.Convert]::ToBase64String((Get-Content -Path $IconPath -AsByteStream -ReadCount 0)) - } - else - { - $base64EncodedImage = [System.Convert]::ToBase64String((Get-Content -Path $iconPath -Encoding Byte -ReadCount 0)) - } - + $base64EncodedImage = [System.Convert]::ToBase64String((Get-Content -Path $iconPath -Encoding Byte -ReadCount 0)) return $("data:$($mimeType);base64,$($base64EncodedImage)") } else @@ -745,15 +736,7 @@ function Compare-M365DSCConfigurations [Array]$DestinationObject = $DestinationObject | Where-Object -FilterScript { $_.ResourceName -notin $ExcludedResources } } - $isPowerShellCore = $PSVersionTable.PSEdition -eq 'Core' - if ($isPowerShellCore) - { - $dscResourceInfo = Get-PwshDSCResource -Module 'Microsoft365DSC' - } - else - { - $dscResourceInfo = Get-DSCResource -Module 'Microsoft365DSC' - } + $dscResourceInfo = Get-DSCResource -Module 'Microsoft365DSC' # Loop through all items in the source array $i = 1 foreach ($sourceResource in $SourceObject) diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index e76c114761..1411a55cac 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -23,7 +23,6 @@ Internal, Hidden function Format-EXOParams { [CmdletBinding()] - [OutputType([System.Collections.Hashtable])] param ( [Parameter()] @@ -1452,7 +1451,6 @@ function Export-M365DSCConfiguration } $Script:M365DSCDependenciesValidated = $false -$Script:IsPowerShellCore = $PSVersionTable.PSEdition -eq 'Core' <# .Description @@ -1479,7 +1477,7 @@ function Confirm-M365DSCDependencies { $ErrorMessage += ' * ' + $invalidDependency.ModuleName + "`r`n" } - $ErrorMessage += 'Please run Update-M365DSCDependencies as Administrator.' + $ErrorMessage += 'Please run Update-M365DSCDependencies with scope "currentUser" or as Administrator.' $ErrorMessage += 'Please run Uninstall-M365DSCOutdatedDependencies.' $Script:M365DSCDependenciesValidated = $false Add-M365DSCEvent -Message $ErrorMessage -EntryType 'Error' ` @@ -1524,11 +1522,6 @@ function Import-M365DSCDependencies foreach ($dependency in $dependencies) { - if ($dependency.PowerShellCore -and -not $Script:IsPowerShellCore) - { - Write-Verbose -Message "Skipping module {$($dependency.ModuleName)} as it is not compatible with Windows PowerShell." - continue - } Import-Module $dependency.ModuleName -RequiredVersion $dependency.RequiredVersion -Force -Global:$Global } } @@ -1587,7 +1580,6 @@ Internal function Get-M365DSCTenantDomain { [CmdletBinding(DefaultParameterSetName = 'AppId')] - [OutputType([System.String])] param ( [Parameter(ParameterSetName = 'AppId', Mandatory = $true)] @@ -3104,11 +3096,6 @@ function Update-M365DSCDependencies { if (-not $Force) { - if ($dependency.PowerShellCore -and -not $Script:IsPowerShellCore) - { - Write-Verbose -Message "The dependency {$($dependency.ModuleName)} requires PowerShell Core. Skipping." - continue - } $found = Get-Module $dependency.ModuleName -ListAvailable | Where-Object -FilterScript { $_.Version -eq $dependency.RequiredVersion } } @@ -3125,22 +3112,10 @@ function Update-M365DSCDependencies } catch { - Write-Verbose -Message "Couldn't retrieve Windows Principal. One possible cause is that the current environment is not a Windows OS." + Write-Verbose -Message "Couldn't retrieve Windows Principal. One possible cause is that the current environment is not Windows OS." } if (-not $errorFound) { - if ($null -eq $dependency.PowerShellCore -and $Script:IsPowerShellCore) - { - Write-Warning "The dependency {$($dependency.ModuleName)} does not support PowerShell Core. Please install it in Windows PowerShell." - continue - } - - if ($dependency.PowerShellCore -and -not $Script:IsPowerShellCore) - { - Write-Warning "The dependency {$($dependency.ModuleName)} requires PowerShell Core. Please install it in PowerShell Core." - continue - } - Write-Information -MessageData "Installing $($dependency.ModuleName) version {$($dependency.RequiredVersion)}" Remove-Module $dependency.ModuleName -Force -ErrorAction SilentlyContinue if ($dependency.ModuleName -like 'Microsoft.Graph*') @@ -3152,19 +3127,6 @@ function Update-M365DSCDependencies } } - if ($dependency.ExplicitLoading) - { - Remove-Module $dependency.ModuleName -Force -ErrorAction SilentlyContinue - if ($dependency.Prefix) - { - Import-Module $dependency.ModuleName -Global -Prefix $dependency.Prefix -Force - } - else - { - Import-Module $dependency.ModuleName -Global -Force - } - } - if (-not $found -and $validateOnly) { $returnValue += $dependency @@ -3621,14 +3583,7 @@ function Get-M365DSCExportContentForResource { if ($Script:AllM365DscResources.Count -eq 0) { - if ($Script:IsPowerShellCore) - { - $Script:AllM365DscResources = Get-PwshDscResource -Module 'Microsoft365Dsc' - } - else - { - $Script:AllM365DscResources = Get-DscResource -Module 'Microsoft365Dsc' - } + $Script:AllM365DscResources = Get-DscResource -Module 'Microsoft365Dsc' } $Resource = $Script:AllM365DscResources.Where({ $_.Name -eq $ResourceName }) @@ -4373,14 +4328,7 @@ function Create-M365DSCResourceExample $ResourceName ) - if ($Script:IsPowerShellCore) - { - $resource = Get-PwshDscResource -Name $ResourceName - } - else - { - $resource = Get-DscResource -Name $ResourceName - } + $resource = Get-DscResource -Name $ResourceName $params = Get-DSCFakeParameters -ModulePath $resource.Path @@ -4465,14 +4413,7 @@ function New-M365DSCMissingResourcesExample { $location = $PSScriptRoot - if ($Script:IsPowerShellCore) - { - $m365Resources = Get-PwshDscResource -Module Microsoft365DSC | Select-Object -ExpandProperty Name - } - else - { - $m365Resources = Get-DscResource -Module Microsoft365DSC | Select-Object -ExpandProperty Name - } + $m365Resources = Get-DscResource -Module Microsoft365DSC | Select-Object -ExpandProperty Name $examplesPath = Join-Path $location -ChildPath '..\Examples\Resources' $examples = Get-ChildItem -Path $examplesPath | Where-Object { $_.PsIsContainer } | Select-Object -ExpandProperty Name @@ -4828,14 +4769,7 @@ function Get-M365DSCConfigurationConflict $parsedContent = ConvertTo-DSCObject -Content $ConfigurationContent $resourcesPrimaryIdentities = @() - if ($Script:IsPowerShellCore) - { - $resourcesInModule = Get-PwshDSCResource -Module 'Microsoft365DSC' - } - else - { - $resourcesInModule = Get-DSCResource -Module 'Microsoft365DSC' - } + $resourcesInModule = Get-DSCResource -Module 'Microsoft365DSC' foreach ($component in $parsedContent) { $resourceDefinition = $resourcesInModule | Where-Object -FilterScript {$_.Name -eq $component.ResourceName} diff --git a/Tests/TestHarness.psm1 b/Tests/TestHarness.psm1 index a1ccd89269..ecc798f884 100644 --- a/Tests/TestHarness.psm1 +++ b/Tests/TestHarness.psm1 @@ -38,7 +38,6 @@ function Invoke-TestHarness } Import-Module -Name "$repoDir/Modules/Microsoft365DSC/Microsoft365DSC.psd1" - Import-Module -Name PSDesiredStateConfiguration -Global -Prefix 'Pwsh' -Force $testsToRun = @() # Run Unit Tests diff --git a/docs/docs/user-guide/get-started/powershell7-support.md b/docs/docs/user-guide/get-started/powershell7-support.md index b12e6f1041..cb869406b4 100644 --- a/docs/docs/user-guide/get-started/powershell7-support.md +++ b/docs/docs/user-guide/get-started/powershell7-support.md @@ -41,10 +41,10 @@ that location or use PowerShell 5.1 to install the modules using 'Install-Module Connect-PnPOnline: Could not load file or assembly 'System.IdentityModel.Tokens.Jwt, Version=6.12.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Could not find or load a specific file. (0x80131621) ``` -# PSDesiredStateConfiguration needs to be installed separately +# PSDesiredStateConfiguration Needs to be Installed Separately -Starting with PowerShell 7.2, the core Desired State Configuration module (PSdesiredStateConfiguration) has been decoupled from the core PowerShell build and now needs to be installed separately. In an administrative PowerShell 7+ console, you can install the module by running the command: +Starting with PowerShell 7.2, the core Desired State Configuration module (PSdesiredStateConfiguration) has been decoupled from the core PowerShell build and now need to be installed separately. In a PowerShell 7+ console, you can install the module by running the command: ```powershell -Update-M365DSCDependencies -Scope AllUsers +Install-Module PSDesiredStateConfiguration -Force ```