{"id":18048130,"url":"https://github.com/startautomating/poshmacros","last_synced_at":"2025-04-10T09:49:39.397Z","repository":{"id":80535893,"uuid":"239384123","full_name":"StartAutomating/PoshMacros","owner":"StartAutomating","description":"Sleek and Simple PowerShell Macros","archived":false,"fork":false,"pushed_at":"2020-02-09T23:03:27.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T08:46:08.011Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PowerShell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StartAutomating.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-09T22:28:59.000Z","updated_at":"2023-09-16T19:02:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"c4d4b711-a8c6-4de8-b755-bda16ec5a771","html_url":"https://github.com/StartAutomating/PoshMacros","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FPoshMacros","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FPoshMacros/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FPoshMacros/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StartAutomating%2FPoshMacros/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StartAutomating","download_url":"https://codeload.github.com/StartAutomating/PoshMacros/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248197464,"owners_count":21063619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-30T20:11:42.665Z","updated_at":"2025-04-10T09:49:39.372Z","avatar_url":"https://github.com/StartAutomating.png","language":"PowerShell","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿\nPoshMacros [0.1]\n================\nSleek and Simple PowerShell Macros\n----------------\n### Commands\n---------------\n|  Verb|Noun  |\n|-----:|:-----|\n|   Add|-Macro|\n|Export|-Macro|\n|   Get|-Macro|\n|Import|-Macro|\n|Remove|-Macro|\n---------------\nPoshMacros is a module to help build useful command line macros in PowerShell\n\nMacro functions are quick commands that tend to start with an _.  They can be a:\n\n* -Path (to a file or folder)\n* -Alias\n* -Command proxies (these can -RemoveParameter(s), have -OptionalParameter(s) and have -DefaultParameter(s))\n* -ScriptBlock\n* -URI (with variables in enclosed in curly brackets or braces, or preceeded by a dollar sign or colon)\n\n### Defining Macros\n\nMacros are defined with Add-Macro.  Add-Macro is aliased to _+.\n\n#### Path Macros\n\nYou can define path macros.  These work like named directories in certain advanced shells:\n* Running the command pushes into the directory (if already there, it echoes).\n* Assigning the command returns the [IO.DirectoryInfo]\n~~~\n# Define a path macro.  Running this will pop you into the PoshMacros directory.  Assigning it will return the [IO.DirectoryInfo].\nAdd-Macro -Name PoshMacrosRoot -Path (Get-Module PoshMacros | Split-Path)\n~~~\n\nShowUI\\New-Path Macros can also point to files.\n\nIf the file one of a few data file types, the data will be returned:\n* .CSV | .TSV (using Import-CSV)\n* .CLIXML | .CLIX (using Import-Clixml)\n* .JSON (using ConvertFrom-JSON)\n* .svg | *.xml (by casting to [xml])\n* .psd1 (using Import-LocalizedData)\n* .ps1 (as an ExternalScript)\n* .md | .htm[l] | .txt\n~~~\nAdd-Macro -Name PesterManifest -Path (Get-Module Pester | Split-Path | Join-Path -ChildName 'Pester.psd1')\n~~~\n\n#### Aliases, Proxy Commands, and Script Blocks\n\nYou can also define aliases.  These act just like any other alias in PowerShell:\n\n~~~\nAdd-Macro -Name Now -Alias Get-Date\n_Now\n~~~\n\nYou can also define a proxy -Command.  If you provide a variable name as a default value, it will be expanded when the proxy runs.\n\n~~~\nAdd-Macro -Name MyProcess -Command Get-Process -DefaultParameter @{Id='$pid'} -RemoveParameter *\n_MyProcess\n~~~\n\nYou can also define a macro as an arbitrary -ScriptBlock\n\n~~~\nAdd-Macro -Name Today -ScriptBlock { [DateTime]::Now.Date }\n_Today\n~~~\n\n#### URI Macros\n\nYou can define a macro for a -URI with embedded variables.  As the example below makes clear, you can include\n\n~~~\nAdd-Macro -Name GitRepos -Uri 'https://api.github.com/users/:username/repos?page={page}\u0026per_page=$perPage' -DefaultParameter @{\n    page = 1\n    perpage = 50\n}\n\n$StartAutomatingRepos = _GitRepos -UserName StartAutomating\n~~~\n\nLike path macros, URI macros work differently when assigned or piped (at least on Windows).\n\nOn Windows, running a URI macro without assigning or piping will open the URL in a browser.\n\nURI macros wrap Invoke-RestMethod, and will carry over all parameters from Invoke-RestMethod except for the URI.\n\nProviding any of these parameters will override\n\n### Getting Macros\n\nEach Macro is defined in a dynamic module, so you can get macros either by running Get-Macro or Get-Module -Name NameOfMacro\n\n~~~\nGet-Macro\n~~~\n\n~~~\nGet-Macro -Prefix '_' # Gets all macros with the prefix _\n~~~\n\n### Exporting Macros\n\nYou can use Export-Macro to export a macro definition.  These can be re-imported at any time, independently of the PoshMacros \nmodule.\n\n~~~\nAdd-Macro -Name MyProcess -Command Get-Process -DefaultParameter @{Id='$pid'} -RemoveParameter *\n\nExport-Macro -Name MyProcess\n~~~\n\nBy default, Export-Macro will declare the dynamic module and metadata associated with a macro.\nYou can also simply export function definitions and aliases with -Inline.\n\n~~~\nAdd-Macro -Name Now -Alias Get-Date\n\nExport-Macro -Name Now -Inline\n~~~\n\n### Importing Macros\n\nMacros can be defined within a module by adding a .PoshMacros section of a module's PrivateData, or attaching a .PoshMacros \nproperty to a module.\n\nTo see an example of this in action, use:\n\n~~~\nImport-Macro -Name PoshMacros -PassThru\n~~~\n\nYou can examine the PrivateData of PoshMacros with:\n\n~~~\n(_PoshMacrosManifest).PrivateData.PoshMacros\n~~~\n\nAny modules that have PoshMacros will be automatically imported when PoshMacros loads.\n\n\n### Removing Macros\n\nRemove-Macro will undeclare macros:\n\n~~~\nAdd-Macro -Name Now -ScriptBlock { [DateTime]::Now }\n_Now # it works\nRemove-Macro -Name _Now\n_Now # it doesn't\n~~~\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartautomating%2Fposhmacros","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstartautomating%2Fposhmacros","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstartautomating%2Fposhmacros/lists"}