Last active
January 22, 2026 15:53
-
-
Save SQLDBAWithABeard/335ed702886be3f8d26ddb3d0c67f654 to your computer and use it in GitHub Desktop.
CopyModuleForTesting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Fasten your seatbelts. It's going to be a bumpy night. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Copy-ModuleForTesting { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter()] | |
| [string]$SourceModuleName = "MicrosoftFabricMgmt", | |
| [Parameter()] | |
| [string]$NewModuleName = "Test-MicrosoftFabricMgmt", | |
| [Parameter()] | |
| [string]$Version = "1.0.1", | |
| [Parameter()] | |
| [string]$TargetRoot = "S:\temp\PSModules" | |
| ) | |
| # Resolve source module path | |
| $sourceModule = Get-Module $SourceModuleName -ListAvailable | Select-Object -First 1 | |
| if (-not $sourceModule) { | |
| throw "Module '$SourceModuleName' not found in PSModulePath." | |
| } | |
| $sourcePath = Split-Path $sourceModule.Path -Parent | |
| # Build destination path: <TargetRoot>\<NewModuleName>\<Version>\ | |
| $destBase = Join-Path $TargetRoot $NewModuleName | |
| $destPath = Join-Path $destBase $Version | |
| # Ensure destination exists | |
| if (-not (Test-Path $destPath)) { | |
| New-Item -ItemType Directory -Path $destPath -Force | Out-Null | |
| } | |
| # Copy module contents | |
| Copy-Item -Recurse -Force "$sourcePath\*" $destPath | |
| # Fix manifest | |
| $oldManifest = Join-Path $destPath "$SourceModuleName.psd1" | |
| $newManifest = Join-Path $destPath "$NewModuleName.psd1" | |
| # Fix manifest | |
| $oldManifestm = Join-Path $destPath "$SourceModuleName.psm1" | |
| $newManifestm = Join-Path $destPath "$NewModuleName.psm1" | |
| if (Test-Path $oldManifestm -ErrorAction SilentlyContinue) { | |
| Rename-Item $oldManifestm $newManifestm -Force | |
| } else { | |
| throw "Manifest file '$oldManifestm' not found." | |
| } | |
| $manifest = Import-PowerShellDataFile -Path $oldManifest | |
| $manifest.ModuleVersion = $Version | |
| $manifest.Path = $newManifest | |
| $manifest.RootModule = "$NewModuleName.psm1" | |
| if ($manifest.PrivateData.PSData.LicenseUri) { | |
| $manifest.LicenseUri = $manifest.PrivateData.PSData.LicenseUri | |
| } | |
| if ($manifest.PrivateData.PSData.ProjectUri) { | |
| $manifest.ProjectUri = $manifest.PrivateData.PSData.ProjectUri | |
| } | |
| if ($manifest.PrivateData.PSData.IconUri) { | |
| $manifest.IconUri = $manifest.PrivateData.PSData.IconUri | |
| } | |
| if ($manifest.PrivateData.PSData.Tags) { | |
| $manifest.Tags = $manifest.PrivateData.PSData.Tags | |
| } | |
| if ($manifest.PrivateData.PSData.ReleaseNotes) { | |
| $manifest.ReleaseNotes = $manifest.PrivateData.PSData.ReleaseNotes | |
| } | |
| if ($manifest.PrivateData.PSData.RequireLicenseAcceptance) { | |
| $manifest.RequireLicenseAcceptance = $manifest.PrivateData.PSData.RequireLicenseAcceptance | |
| } | |
| if ($manifest.PrivateData.PSData.ExternalModuleDependencies) { | |
| $manifest.ExternalModuleDependencies = $manifest.PrivateData.PSData.ExternalModuleDependencies | |
| } | |
| $manifest.PrivateData = $null | |
| New-ModuleManifest @manifest | |
| # Add base folder to PSModulePath if needed | |
| if ($env:PSModulePath -notlike "*$TargetRoot*") { | |
| $env:PSModulePath = "$TargetRoot;" + $env:PSModulePath | |
| } | |
| Remove-Item $oldManifest -Force | |
| return $destPath | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment