Anything can be a package.
This command helps you make anything into a package.
The following types of packages are currently supported:
- Any Open Packaging Convention files
- Any directory
- Any
*.zipfile - Any
*.tar.gzfile - Any nuget package
- Any git repository
- Any public at protocol URI
- Any dictionary (including nested dictionaries)
- Any url
- Any file
Anything can be a package.
Once we start to treat anything as a package, we can do amazing things with packages.
Like:
- Inspect any packages before we work with them.
- Modify the packages to customize their content.
- Split packages
- Filter our components.
- Join them back together.
- Search package content.
- Work with compressed trees of data.
- Have an in-memory containerized virtual filesystem.
- Serve a package from memory.
- Store data to N package layers.
To put it simply, open packages are overpowered.
You can install OP from the PowerShell gallery
Install-Module OP -Scope CurrentUser -ForceOnce installed, you can import the module with:
Import-Module OP -PassThruYou can also clone the repo and import the module locally:
git clone https://github.com/PoshWeb/OP
cd ./OP
Import-Module ./ -PassThruOP has 17 functions
Copies Contents from one packages to another.
Copy-OpenPackage -DestinationPath ./Examples/Copy.docx -InputObject ./Examples/Sample.docx -Force| Name | Type | Description |
|---|---|---|
| Destination | PSObject | The destination. If this is not a [IO.Packaging.Package], it will be considered a file path. |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| ExcludeContentType | String[] | Excludes the specified content types. Enter a wildcard pattern, such as text/* |
| InputObject | PSObject | The input object |
| Force | SwitchParameter | If set, will update existing packages. |
Exports loaded packages to a file or directory.
| Name | Type | Description |
|---|---|---|
| DestinationPath | String | The package file path. If this has no extension, it will be considered a directory name. If the path already exists and is a directory, it will be considered a directory name. |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txt |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txt |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| InputObject | PSObject | The input object. This must be a package loaded with this module. |
| Force | SwitchParameter | If set, will force the export even if a file already exists. |
Formats Open Packages using any view.
| Name | Type | Description |
|---|---|---|
| View | PSObject | The name of the view, or a view command or scriptblock |
| ArgumentList | PSObject[] | The Any Positional arguments for the view |
| InputObject | PSObject[] | Any input objects. |
| Option | IDictionary | Any options or parameters to pass to the View |
Gets Open Packages from almost anything.
Anything can be a package.
This command helps you make anything into a package.
The following types of packages are currently supported:
- Any Open Packaging Convention files
- Any directory
- Any
*.zipfile - Any
*.tar.gzfile - Any url
- Any public nuget package
- Any git repository
- Any public at protocol URI
- Any dictionary (including nested dictionaries)
- Any single file
Anything can be a package.
Once we start to treat anything as a package, we can do amazing things with packages.
Like:
- Inspect any packages before we work with them.
- Modify the packages to customize their content.
- Split packages
- Filter our components.
- Join them back together.
- Search package content.
- Work with compressed trees of data.
- Have an in-memory containerized virtual filesystem.
- Serve a package from memory.
- Store data to N package layers.
Make the current directory into a package
(do not try this at $home)
Get-OpenPackage .Make the module into a package
$opPackage = Get-Module OP | Get-OpenPackage$opPackage = Get-Module OP |
Get-OpenPackage -Include *.ps1Another way to make the current directory into a package
(do not try this at $home)
Get-Item . | Get-OpenPackageGet a package from nuget
$Avalonia = OP https://www.nuget.org/packages/Avalonia/Get a package from Chocolatey
$chocoPackage = op https://community.chocolatey.org/packages/chocolateyGet a package from the PowerShell gallery
$turtlePackage = op https://powershellgallery.com/packages/TurtleGet a package from a single URL
$imagePackage = op https://MrPowerShell.com/MrPowerShell.pngCreate a package from multiple URLs by piping back to ourself
$svgAndPng = op https://MrPowerShell.com/MrPowerShell.png |
op https://MrPowerShell.com/MrPowerShell.svgGet a package from an at protocol URI
$atPost = op at://mrpowershell.com/app.bsky.feed.post/3k4hf5dy6nf2gGet the most recent 50 posts
$atLast50 = op at://mrpowershell.com/app.bsky.feed.post/ -First 50Get all standard.site.documents for a user
$standardSiteDocuments = op at://mrpowershell.com/site.standard.document/| Name | Type | Description |
|---|---|---|
| ArgumentList | PSObject[] | Any unnamed arguments to the command. Each argument will be treated as a potential -FilePath or -Uri. Once the first related verb is detected, these will become arguments to that verb (For example, op . start will get an open package and then start a server for that package) |
| FilePath | String | The path of a file to import |
| At | String[] | Gets Open Packages with @ syntax.Without a domain, @ will be presumed to be a githubWith a domain, @ will look for an https url, and check at protocol |
| Uri | Uri[] | A URI to package. If this URI is a git repository, will make a package out of the repository If this URI is a nuget package url or powershell gallery url, will download the package. |
| Headers | IDictionary | Any additional headers to pass into a web request. |
| Repository | String | A Repository to package. This can be the root of a repo or a link to a portion of the tree. If a portion of the tree is provided, will perform a sparse clone of the repository |
| Branch | String | The github branch name. |
| SparseFilter | String[] | One or more optional sparse filters to a repository. If these are provided, only files matching these filters will be downloaded. |
| AtUri | String[] | An At Uri to package. This can be a single post or a collection of all posts of a type. |
| PDS | String | The personal data server. This is used in At Protocol requests. |
| Dictionary | IDictionary | Adds a dictionary of content to the package |
| BasePath | String | The base path within the package. Content should be added beneath this base path. |
| NuGet | Uri | A Nuget Uri to package. The package at this location will be downloaded and opened directly. |
| NodePackage | String[] | One or more Node Packages. |
| PythonPackage | String[] | One or more Python Packages. |
| Module | PSObject | A module to package A loaded module name or moduleinfo object to package. The loaded module must have a path property. The files in this path will be packaged. |
| Include | String[] | A list of file wildcards to include. |
| Exclude | String[] | A list of file wildcards to exclude. |
| TypeMap | IDictionary | A content type map. This maps extensions and URIs to a content type. |
| CompressionOption | CompressionOption | The compression option. |
| InputObject | PSObject | One or more input objects. |
| Installed | SwitchParameter | Gets the packages that are currently installed |
| Running | SwitchParameter | Gets packages that are currently running in a server |
| Force | SwitchParameter | If set, will force the redownload of various resources and remove existing files or directories |
| IncludeHidden | SwitchParameter | If set, will include hidden files and folders, except for files beneath .git |
| IncludeGit | SwitchParameter | If set, will include the .git directory contents if found.By default, this content will be excluded. |
| IncludeNodeModule | SwitchParameter | If set, will include any content found in /node_modules.By default, this content will be excluded. |
| IncludeSite | SwitchParameter | If set, will include any content found in /_site.By default, this content will be excluded. |
| IncludeTotalCount | SwitchParameter | |
| Skip | UInt64 | |
| First | UInt64 |
Installs an OpenPackage into a destination on disk.
| Name | Type | Description |
|---|---|---|
| ArgumentList | PSObject[] | The arguments to Get-OpenPackage. |
| DestinationPath | String | The destination path. If provided, this should be a directory, but can be a file. If multiple packages will be installed and a -DestinationPath was provided, all packages will be installed into that destination path. If no destination path is provided, only packages with an identifier will be installed. Packages will install beneath the first $env:OpenPackagePath.If the package has a version, it will install into a versioned subdirectory. |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txt |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txt |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| ExcludeContentType | String[] | Excludes the specified content types. Enter a wildcard pattern, such as text/* |
| InputObject | PSObject | The input object. If this is not a package, it will be passed thru. |
| Force | SwitchParameter | If set, will overwrite existing files. |
| Clear | SwitchParameter | If set, will clear the destination directory before installing. |
| PassThru | SwitchParameter | If set, will output the files that are expanded from the package. |
| WhatIf | SwitchParameter | |
| Confirm | SwitchParameter |
Joins multiple open packages into a single open package
| Name | Type | Description |
|---|---|---|
| InputObject | PSObject | |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| ExcludeContentType | String[] | Excludes the specified content types. Enter a wildcard pattern, such as text/* |
| Force | SwitchParameter |
Locks an Open Package.
Closes the package and copies it into a read-only package.
Import OP, make it a package, and lock it
Import-Module OP -PassThru |
Get-OpenPackage |
Lock-OpenPackageImport OP, make it a package, and lock it
impo OP -PassThru | op | lkop| Name | Type | Description |
|---|---|---|
| InputObject | PSObject | The input object. This should be a package. |
Creates an new empty open package
Publishes Open Packages using any OpenPackage.Publisher or command.
| Name | Type | Description |
|---|---|---|
| Publisher | PSObject[] | The name of the Publisher, or a command or script block used to Publish. One or more publishers may be provided. They will be processed in the order provided. |
| ArgumentList | PSObject[] | The Any Positional arguments for the view |
| InputObject | PSObject[] | Any input objects. |
| Option | IDictionary | Any options to pass to the View |
| WhatIf | SwitchParameter | |
| Confirm | SwitchParameter |
Reads Bytes within an Open Package
$package = OP @{"hello.txt" = "Hello world"}
$package |
Read-OpenPackage -Uri /hello.txt$package = OP @{"hello.txt" = "Hello world"}
($package |
Read-OpenPackage -Uri /hello.txt -RangeStart 0 -RangeEnd 5) -as 'char[]'$package = OP @{"hello.txt" = "Hello world"}
($package |
Read-OpenPackage -Uri /hello.txt -RangeStart 0 -RangeEnd 5) -as 'char[]' -join ''| Name | Type | Description |
|---|---|---|
| Uri | Uri[] | One or more part uris |
| RangeStart | Int64 | A start range |
| RangeEnd | Int64 | An ending range |
| InputObject | PSObject | The input object. If this is not a package, it will be passed thru. |
Removes content parts from an open package.
Get-OpenPackage @{
"a.html" = "<h1>a html file</h1>"
} |
Remove-OpenPackage -Uri '/a.html'Get-OpenPackage @{
"a.html" = "<h1>a html file</h1>"
"a.css" = "body { max-width: 100vw; height: 100vh}"
} |
Select-OpenPackage -Include *.html |
Remove-OpenPackage| Name | Type | Description |
|---|---|---|
| Uri | Uri[] | One or more URIs to remove |
| InputObject | PSObject | The input object. If this is not a package, the input will be passed thru and nothing will be removed. |
| WhatIf | SwitchParameter | |
| Confirm | SwitchParameter |
Selects content from an Open Package using Regular Expressions or XPath
| Name | Type | Description |
|---|---|---|
| Pattern | PSObject[] | A list of patterns to match. |
| SimpleMatch | SwitchParameter | Indicates that the cmdlet uses a simple match rather than a regular expression match. |
| CaseSensitive | SwitchParameter | Indicates that the cmdlet matches are case-sensitive. By default, pattern matches aren't case-sensitive. |
| Quiet | SwitchParameter | Indicates that the cmdlet returns a simple response instead of a [MatchInfo] object.The returned value is $true if the pattern is found or $null if the pattern is not found. |
| List | SwitchParameter | Only the first instance of matching text is returned from each input file. This is the most efficient way to retrieve a list of files that have contents matching the regular expression. |
| NoEmphasis | SwitchParameter | By default, Select-String highlights the string that matches the pattern you searched for with the-Pattern parameter. The -NoEmphasis parameter disables the highlighting. |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| ExcludeContentType | String[] | Excludes the specified content types. Enter a wildcard pattern, such as text/* |
| NotMatch | SwitchParameter | The -NotMatch parameter finds text that doesn't match the specified pattern. |
| AllMatches | SwitchParameter | Indicates that the cmdlet searches for more than one match in each line of text. Without this parameter, Select-String finds only the first match in each line of text.When Select-String finds more than one match in a line of text, it still emits only one[MatchInfo] object for the line, but the .Matches property of the object contains all thematches. |
| Context | Int32[] | Captures the specified number of lines before and after the line that matches the pattern. If you enter one number as the value of this parameter, that number determines the number of lines captured before and after the match. If you enter two numbers as the value, the first number determines the number of lines before the match and the second number determines the number of lines after the match. For example, -Context 2,3. |
| Raw | SwitchParameter | Causes the cmdlet to output only the matching strings, rather than MatchInfo objects. This is the results in behavior that's the most similar to the Unix grep or Windows findstr.exe commands. |
| XPath | PSObject | Specifies an XPath search query. The query language is case-sensitive. |
| Namespace | IDictionary | Specifies a hash table of the namespaces used in the XML. Use the format @{<namespaceName> = <namespaceValue>}.When the XML uses the default namespace, which begins with xmlns, use an arbitrary key for the namespace name. You cannot use xmlns. In the XPath statement, prefix each node name with the namespace name and a colon, such as //namespaceName:Node. |
| AstCondition | ScriptBlock[] | One or more Abstract Syntax Tree conditions. These will select elements in any PowerShell scripts that match the condition. |
| InputObject | PSObject | The input object. This should be a package. |
Sets content in an Open Packaging Conventions archive.
$miniServer = Get-OpenPackage |
Set-OpenPackage -Uri '/index.html' -Content ([xml]"<h1>Hello World</h1>") -ContentType text/html |
Start-OpenPackage
Start-Process -FilePath $miniServer.Name| Name | Type | Description |
|---|---|---|
| Uri | Uri | The uri to set |
| Content | PSObject | The content to set. |
| ContentType | String | The content type. By default, text/plain |
| Depth | Int32 | The serialization depth. |
| Option | IDictionary | The options used to write the content. |
| InputObject | PSObject | The input object. This must be a package, and it must be writeable. |
| Force | SwitchParameter | Sets a part, even if it already exists. |
Splits Open Packages into multiple parts
Get-Module OP |
OP |
Split-OpenPackage| Name | Type | Description |
|---|---|---|
| Property | PSObject[] | One or more properties to group. |
| Include | String[] | Includes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| Exclude | String[] | Excludes the specified parts. Enter a wildcard pattern, such as *.txtWildcards are permitted. |
| IncludeContentType | String[] | Includes the specified content types. Enter a wildcard pattern, such as text/* |
| ExcludeContentType | String[] | Excludes the specified content types. Enter a wildcard pattern, such as text/* |
| InputObject | PSObject |
Starts a server, using one or more archive packages as the storage.
| Name | Type | Description |
|---|---|---|
| ArgumentList | PSObject[] | The path to an Open Package file, or a glob that matches multiple Open Package files. |
| RootUrl | String | The root url. By default, this will be automatically to a random local port. If running elevated, can be any valid http listener prefix, including http://*/ |
| InputObject | PSObject[] | The input object. This can be provided to avoid loading a file from disk. |
| Allow | String[] | The allowed http verbs. |
| TypeMap | IDictionary | The content type map |
| Invokable | SwitchParameter | If set, the scripts in the package will be invokable. This turns allows every PowerShell script in the package into server side code. This should be used cautiously, and only with known packages. |
| ThrottleLimit | UInt16 | The throttle limit. This is the number of concurrent jobs that can be running at once. |
| BufferSize | UInt32 | The buffer size. If parts are smaller than this size, they will be streamed. If parts are larger than this size, they will be handled in the background (and may use a buffer of this size when accepting range requests) |
| Lifespan | TimeSpan | The lifespan of the server. If provided, will automatically stop the server after it's life is over. |
| NodeCount | Byte | The number of nodes to run. Each node can handle incoming requests. |
Uninstalls one or more OpenPackages.
| Name | Type | Description |
|---|---|---|
| Identifier | String[] | The package identifier. If this is a fully qualified directory or file name, it will be removed. |
| Version | String[] | The package version |
| PackagePath | String[] | The direct path to any number of packages. This will Remove-Item these paths |
| PackageRoot | String[] | The root location where packages are stored. By default, this will be the locations specified in $env:OpenPackagePath |
| WhatIf | SwitchParameter | |
| Confirm | SwitchParameter |
Writes bytes directly to an Open Package part. The part must already exist.
This can be used to rapidly update small segments of a package.
It can also corrupt package contents, and should be used with care.
To set package parts, use Set-OpenPackage
$package = OP @{"hello.txt" = "Hello world"}
$package |
Write-OpenPackage -Uri /hello.txt -Buffer ($outputEncoding.GetBytes("y")) |
Get-OpenPackage ./hello.txt| Name | Type | Description |
|---|---|---|
| Uri | Uri | The Package Part Uri. This is the path to the content within a package. |
| Content | PSObject | The content to write. |
| Depth | Int32 | The serialization depth. |
| Option | IDictionary | The options used to write the content. |
| RangeStart | Int64 | The starting location for the write. |
| InputObject | PSObject | The package. |
2025-2026 Start-Automating