Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PSModuleDevelopment/PSModuleDevelopment.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
RootModule = 'PSModuleDevelopment.psm1'

# Version number of this module.
ModuleVersion = '2.2.9.106'
ModuleVersion = '2.2.9.107'

# ID used to uniquely identify this module
GUID = '37dd5fce-e7b5-4d57-ac37-832055ce49d6'
Expand Down
58 changes: 29 additions & 29 deletions PSModuleDevelopment/functions/script/Publish-PSMDScriptFile.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function Publish-PSMDScriptFile
{
<#
<#
.SYNOPSIS
Packages a script with all dependencies and "publishes" it as a zip package.

.DESCRIPTION
Packages a script with all dependencies and "publishes" it as a zip package.
By default, it will be published to the user's desktop.
Expand All @@ -12,30 +12,30 @@
- Modules that are installed in the Windows folder (such as the ActiveDirectory module or other modules associated with server roles) will be ignored.
- PSSnapins will be ignored
- All other modules determined by the commands used will be provided from a repository, packaged in a subfolder and included in the zip file.

If needed, the scriptfile will be modified to add the new modules folder to its list of known folders.
(The source file itself will never be modified)

Use Set-PSMDStagingRepository to create / use a local path for staging modules to provide that way.
This gives you better control over the versions used and better performance.
Also the ability to use this with non-public modules.
Use Publish-PSMDStagedModule to transfer modules from path or another repository into your registered staging repository.

.PARAMETER Path
Path to the scriptfile to publish.
The scriptfile is expected to be UTF8 encoded with BOM, otherwise some characters may end up broken.

.PARAMETER OutPath
The path to the folder where the output zip file will be created.
Defaults to the user's desktop.

.PARAMETER EnableException
This parameters disables user-friendly warnings and enables the throwing of exceptions.
This is less user friendly, but allows catching exceptions in calling scripts.

.EXAMPLE
PS C:\> Publish-PSMDScriptFile -Path 'C:\scripts\logrotate.ps1'

Creates a delivery package for the logrotate.ps1 scriptfile and places it on the desktop
#>
[CmdletBinding()]
Expand All @@ -44,15 +44,15 @@
[PsfValidateScript('PSModuleDevelopment.Validate.File', ErrorString = 'PSModuleDevelopment.Validate.File')]
[string]
$Path,

[PsfValidateScript('PSModuleDevelopment.Validate.Path', ErrorString = 'PSModuleDevelopment.Validate.Path')]
[string]
$OutPath = (Get-PSFConfigValue -FullName 'PSModuleDevelopment.Script.OutPath'),

[switch]
$EnableException
)

begin
{
#region Utility Functions
Expand All @@ -64,10 +64,10 @@
[string]
$Path
)

$help = Get-Help $Path
$modifiers = $help.alertSet.alert.Text -split "`n" | Where-Object { $_ -like "PSMD: *" } | ForEach-Object { $_ -replace '^PSMD: ' }

foreach ($modifier in $modifiers)
{
$operation, $values = $modifier -split ":"
Expand Down Expand Up @@ -106,15 +106,15 @@
}
}
}

function Add-PSModulePath
{
[CmdletBinding()]
param (
[string]
$Path
)

$psmodulePathCode = @'

# Ensure modules are available
Expand All @@ -123,7 +123,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:


'@

$parsedFile = Read-PSMDScript -Path $Path
$assignment = $parsedFile.Ast.FindAll({
$args[0] -is [System.Management.Automation.Language.AssignmentStatementAst] -and
Expand Down Expand Up @@ -155,11 +155,11 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:
}
}
#endregion Utility Functions

$modulesToProcess = @{
IgnoreCommand = @()
Include = @()
Exclude = @()
Include = @()
Exclude = @()
}
}
process
Expand All @@ -171,7 +171,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:
{
$modulesToProcess.$($modifier.Type) += $modifier.Name
}

# Detect modules needed and store them
try { $parsedCommands = Get-PSMDFileCommand -Path $Path -EnableException }
catch
Expand All @@ -183,7 +183,7 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:
{
Write-PSFMessage -Level Verbose -String 'Publish-PSMDScriptFile.Script.Command' -StringValues $command.Name, $command.Count, $command.Module
if ($modulesToProcess.IgnoreCommand -contains $command.Name) { continue }

if (-not $command.Module -and -not $command.Internal)
{
Write-PSFMessage -Level Warning -String 'Publish-PSMDScriptFile.Script.Command.NotKnown' -StringValues $command.Name, $command.Count
Expand All @@ -192,15 +192,15 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:
if ($modulesToProcess.Exclude -contains "$($command.Module)") { continue }
if ($modulesToProcess.Include -contains "$($command.Module)") { continue }
if ($command.Module -is [System.Management.Automation.PSSnapInInfo]) { continue }
if ($command.Module.ModuleBase -eq 'C:\Windows\System32\WindowsPowerShell\v1.0') { continue }
if ($command.Module.ModuleBase -eq 'C:\Program Files\PowerShell\7'){ continue }
if ($command.Module.ModuleBase -like 'C:\Windows\System32\WindowsPowerShell\v1.0*') { continue }
if ($command.Module.ModuleBase -like 'C:\Program Files\PowerShell\7*') { continue }
$modulesToProcess.Include += "$($command.Module)"
}

$tempPath = Get-PSFPath -Name Temp
$newPath = New-Item -Path $tempPath -Name "PSMD_$(Get-Random)" -ItemType Directory -Force
$modulesFolder = New-Item -Path $newPath.FullName -Name 'Modules' -ItemType Directory -Force

foreach ($moduleLabel in $modulesToProcess.Include | Select-Object -Unique)
{
if (-not $moduleLabel) { continue }
Expand All @@ -210,13 +210,13 @@ if (-not $env:PSModulePath.Contains($modulePath)) { $env:PSModulePath = "$($env:
if (Test-PSFFunctionInterrupt) { return }
}
#endregion Prepare required Modules

# Copy script file
$newScript = Copy-Item -Path $Path -Destination $newPath.FullName -PassThru

# Update script to set PSModulePath
Add-PSModulePath -Path $newScript.FullName

# Zip result & move to destination
Compress-Archive -Path "$($newPath.FullName)\*" -DestinationPath ('{0}\{1}.zip' -f $OutPath, $newScript.BaseName) -Force
Remove-Item -Path $newPath.FullName -Recurse -Force -ErrorAction Ignore
Expand Down
1 change: 1 addition & 0 deletions build/vsts-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if (-not $WorkingDirectory)
}
else { $WorkingDirectory = $env:SYSTEM_DEFAULTWORKINGDIRECTORY }
}
if (-not $WorkingDirectory) { $WorkingDirectory = Split-Path $PSScriptRoot }
#endregion Handle Working Directory Defaults

# Prepare publish folder
Expand Down