diff --git a/.github/workflows/CodeCoverage.yml b/.github/workflows/CodeCoverage.yml index 9915db2567..53e4f15664 100644 --- a/.github/workflows/CodeCoverage.yml +++ b/.github/workflows/CodeCoverage.yml @@ -37,6 +37,7 @@ jobs: run: | Install-Module Pester -Force [System.Environment]::SetEnvironmentVariable('M365DSCTelemetryEnabled', $false, [System.EnvironmentVariableTarget]::Machine); + Import-Module './Tests/TestHarness.psm1' -Force; $MaximumFunctionCount = 9999 try { diff --git a/CHANGELOG.md b/CHANGELOG.md index 30e0f69135..05a393c8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # Change log for Microsoft365DSC +## 1.20.1016.1 + +* Fixed a permissions issue with the + Install-M365DSCDevBranch cmdlet (Issue #699 & #826) +* DEPENDENCIES + * MSCloudLoginAssistant Updated to 1.0.41; + * SharePointPnPPowerShellOnline Updated to 3.26.2010.0; +* MISC + * Improved Error log to include StackTrace for additional + info to help troubleshooting errors. + ## 1.20.1014.1 * TeamsVoiceRoute diff --git a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 index fadbe10c85..cdb4422315 100644 --- a/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 +++ b/Modules/Microsoft365DSC/DSCResources/MSFT_SCRetentionCompliancePolicy/MSFT_SCRetentionCompliancePolicy.psm1 @@ -564,7 +564,7 @@ function Set-TargetResource if (('Present' -eq $Ensure) -and ('Absent' -eq $CurrentPolicy.Ensure)) { Write-Verbose -Message "Creating new Retention Compliance Policy $Name" - $CreationParams.Add("Name", $Identity) + $CreationParams.Add("Name", $Name) $CreationParams.Remove("Identity") | Out-Null New-RetentionCompliancePolicy @CreationParams } diff --git a/Modules/Microsoft365DSC/Dependencies/Images/APIPermissions.png b/Modules/Microsoft365DSC/Dependencies/Images/APIPermissions.png new file mode 100644 index 0000000000..057b5c80c6 Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/APIPermissions.png differ diff --git a/Modules/Microsoft365DSC/Dependencies/Images/AppId.png b/Modules/Microsoft365DSC/Dependencies/Images/AppId.png new file mode 100644 index 0000000000..a79747238e Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/AppId.png differ diff --git a/Modules/Microsoft365DSC/Dependencies/Images/CertPath.png b/Modules/Microsoft365DSC/Dependencies/Images/CertPath.png new file mode 100644 index 0000000000..364b87e9a8 Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/CertPath.png differ diff --git a/Modules/Microsoft365DSC/Dependencies/Images/CertificateThump.png b/Modules/Microsoft365DSC/Dependencies/Images/CertificateThump.png new file mode 100644 index 0000000000..c242005bc2 Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/CertificateThump.png differ diff --git a/Modules/Microsoft365DSC/Dependencies/Images/ExportCertThumb.png b/Modules/Microsoft365DSC/Dependencies/Images/ExportCertThumb.png new file mode 100644 index 0000000000..98a54cbe65 Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/ExportCertThumb.png differ diff --git a/Modules/Microsoft365DSC/Dependencies/Images/userpwdpng.png b/Modules/Microsoft365DSC/Dependencies/Images/userpwdpng.png new file mode 100644 index 0000000000..367ae6d13e Binary files /dev/null and b/Modules/Microsoft365DSC/Dependencies/Images/userpwdpng.png differ diff --git a/Modules/Microsoft365DSC/Microsoft365DSC.psd1 b/Modules/Microsoft365DSC/Microsoft365DSC.psd1 index 86ede8e476..f6d04b2dec 100644 --- a/Modules/Microsoft365DSC/Microsoft365DSC.psd1 +++ b/Modules/Microsoft365DSC/Microsoft365DSC.psd1 @@ -3,7 +3,7 @@ # # Generated by: Microsoft Corporation # -# Generated on: 2020-10-14 +# Generated on: 2020-10-16 @{ @@ -11,7 +11,7 @@ # RootModule = '' # Version number of this module. - ModuleVersion = '1.20.1014.1' + ModuleVersion = '1.20.1016.1' # Supported PSEditions # CompatiblePSEditions = @() @@ -93,7 +93,7 @@ }, @{ ModuleName = "MSCloudLoginAssistant" - RequiredVersion = "1.0.40" + RequiredVersion = "1.0.41" }, @{ ModuleName = "ReverseDSC" @@ -101,7 +101,7 @@ }, @{ ModuleName = "SharePointPnPPowerShellOnline" - RequiredVersion = "3.25.2009.1" + RequiredVersion = "3.26.2010.0" } ) diff --git a/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 index 0f82180b6e..ae21b3bb2b 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCLogEngine.psm1 @@ -23,7 +23,7 @@ function New-M365DSCLogEntry try { $VerbosePreference = 'Continue' - Write-Host "$($Global:M365DSCEmojiRedX) Logging a new Error" + Write-Host "$($Global:M365DSCEmojiRedX)" #region Telemetry $driftedData = [System.Collections.Generic.Dictionary[[String], [String]]]::new() @@ -32,6 +32,7 @@ function New-M365DSCLogEntry $driftedData.Add("Exception", $Error.Exception.ToString()) $driftedData.Add("CustomMessage", $Message) $driftedData.Add("Source", $Source) + $driftedData.Add("StackTrace", $Error.ScriptStackTrace) Add-M365DSCTelemetryEvent -Type "Error" -Data $driftedData #endregion @@ -47,10 +48,13 @@ function New-M365DSCLogEntry $LogContent += "{" + $Error.CategoryInfo.Category.ToString() + "}`r`n" $LogContent += $Error.Exception.ToString() + "`r`n" $LogContent += "`"" + $Message + "`"`r`n" + $LogContent += $Error.ScriptStackTrace + "`r`n" $LogContent += "`r`n`r`n" # Write the error content into the log file; + $LogFileName = Join-Path -Path (Get-Location).Path -ChildPath $LogFileName $LogContent | Out-File $LogFileName -Append + Write-Host "Error Log created at {$LogFileName}" -ForegroundColor Cyan } catch { @@ -82,37 +86,37 @@ function Add-M365DSCEvent $LogName = 'M365DSC' - if ([System.Diagnostics.EventLog]::SourceExists($Source)) - { - $sourceLogName = [System.Diagnostics.EventLog]::LogNameFromSourceName($Source, ".") - if ($LogName -ne $sourceLogName) - { - Write-Verbose -Message "[ERROR] Specified source {$Source} already exists on log {$sourceLogName}" - return - } - } - else + try { - if ([System.Diagnostics.EventLog]::Exists($LogName) -eq $false) + if ([System.Diagnostics.EventLog]::SourceExists($Source)) { - #Create event log - $null = New-EventLog -LogName $LogName -Source $Source + $sourceLogName = [System.Diagnostics.EventLog]::LogNameFromSourceName($Source, ".") + if ($LogName -ne $sourceLogName) + { + Write-Verbose -Message "[ERROR] Specified source {$Source} already exists on log {$sourceLogName}" + return + } } else { - [System.Diagnostics.EventLog]::CreateEventSource($Source, $LogName) + if ([System.Diagnostics.EventLog]::Exists($LogName) -eq $false) + { + #Create event log + $null = New-EventLog -LogName $LogName -Source $Source + } + else + { + [System.Diagnostics.EventLog]::CreateEventSource($Source, $LogName) + } } - } - try - { Write-EventLog -LogName $LogName -Source $Source ` -EventID $EventID -Message $Message -EntryType $EntryType } catch { Write-Verbose -Message $_ - Add-M365DSCEvent -Message $_ -EntryType 'Error' ` - -EventID 1 -Source $($MyInvocation.MyCommand.Source) + $Message = "Could not write to event log" + New-M365DSCLogEntry -Error $_ -Message $Message -Source "[M365DSCLogEngine]" } } diff --git a/Modules/Microsoft365DSC/Modules/M365DSCReverseGUI.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCReverseGUI.psm1 index 62b2002f85..6266599757 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCReverseGUI.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCReverseGUI.psm1 @@ -799,7 +799,7 @@ function Show-M365DSCGUI catch { $Message = "Could not initiate the ReverseDSC Extraction" - New-M365DSCLogEntry -Error $_ -Message $Message_ -Source "[M365DSCReverseGUI]" + New-M365DSCLogEntry -Error $_ -Message $Message -Source "[M365DSCReverseGUI]" } }) $panelMenu.Controls.Add($btnExtract); diff --git a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 index 4bbc34ba84..3e9147a2cf 100644 --- a/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 +++ b/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1 @@ -1385,9 +1385,11 @@ function Install-M365DSCDevBranch [CmdletBinding()] param() #region Download and Extract Dev branch's ZIP + Write-Host "Downloading the Zip package..." -NoNewline $url = "https://github.com/microsoft/Microsoft365DSC/archive/Dev.zip" $output = "$($env:Temp)\dev.zip" $extractPath = $env:Temp + "\O365Dev" + Write-Host "Done" -ForegroundColor Green Invoke-WebRequest -Uri $url -OutFile $output @@ -1399,19 +1401,41 @@ function Install-M365DSCDevBranch $dependencies = $manifest.RequiredModules foreach ($dependency in $dependencies) { - Install-Module $dependency.ModuleName -RequiredVersion $dependency.RequiredVersion -Force -AllowClobber - Import-Module $dependency.ModuleName -Force + Write-Host "Installing {$($dependency.ModuleName)}..." -NoNewLine + $existingModule = Get-Module $dependency.ModuleName -ListAvailable | Where-Object -FilterScript {$_.Version -eq $dependency.RequiredVersion} + if ($null -eq $existingModule) + { + Install-Module $dependency.ModuleName -RequiredVersion $dependency.RequiredVersion -Force -AllowClobber | Out-Null + } + Import-Module $dependency.ModuleName -Force | Out-Null + Write-Host "Done" -ForegroundColor Green } #endregion #region Install M365DSC + Write-Host "Updating the Core Microsoft365DSC module..." -NoNewline $defaultPath = 'C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\' $currentVersionPath = $defaultPath + ([Version]$($manifest.ModuleVersion)).ToString() + + Copy-Item "$extractPath\Microsoft365DSC-Dev\Modules\Microsoft365DSC\*" ` + -Destination $defaultPath -Recurse -Force + + Import-Module ($defaultPath + "Microsoft365DSC.psd1") -Force | Out-Null + $oldModule = Get-Module 'Microsoft365DSC' | Where-Object -FilterScript {$_.ModuleBase -eq $currentVersionPath} + Remove-Module $oldModule -Force | Out-Null if (Test-Path $currentVersionPath) { - Remove-Item $currentVersionPath -Recurse -Confirm:$false + try + { + Remove-Item $currentVersionPath -Recurse -Confirm:$false -Force ` + -ErrorAction Stop + } + catch + { + Write-Verbose $_ + } } - Copy-Item "$extractPath\Microsoft365DSC-Dev\Modules\Microsoft365DSC" -Destination $currentVersionPath -Recurse -Force + Write-Host "Done" -ForegroundColor Green #endregion }