{"id":22959193,"url":"https://github.com/santisq/psusing","last_synced_at":"2025-08-13T05:31:35.283Z","repository":{"id":267702824,"uuid":"900428391","full_name":"santisq/PSUsing","owner":"santisq","description":"C# using statement for PowerShell","archived":false,"fork":false,"pushed_at":"2024-12-11T22:46:05.000Z","size":44,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-11T23:27:06.114Z","etag":null,"topics":["csharp","disposable","powershell","using"],"latest_commit_sha":null,"homepage":"https://www.powershellgallery.com/packages/PSUsing","language":"C#","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/santisq.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":"2024-12-08T18:45:04.000Z","updated_at":"2024-12-11T22:46:09.000Z","dependencies_parsed_at":"2024-12-11T23:37:44.823Z","dependency_job_id":null,"html_url":"https://github.com/santisq/PSUsing","commit_stats":null,"previous_names":["santisq/psusing"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santisq%2FPSUsing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santisq%2FPSUsing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santisq%2FPSUsing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/santisq%2FPSUsing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/santisq","download_url":"https://codeload.github.com/santisq/PSUsing/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229737479,"owners_count":18116456,"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":["csharp","disposable","powershell","using"],"created_at":"2024-12-14T18:16:13.717Z","updated_at":"2024-12-14T18:16:20.258Z","avatar_url":"https://github.com/santisq.png","language":"C#","readme":"\u003ch1 align=\"center\"\u003ePSUsing\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n\u003csub\u003e\n\n[C# `using` statement][csusing] for PowerShell\n\n\u003c/sub\u003e\n\u003cbr/\u003e\n\n[![build][build_badge]][build_ref]\n[![codecov][codecov_badge]][codecov_ref]\n[![PowerShell Gallery][gallery_badge]][gallery_ref]\n[![LICENSE][license_badge]][license_ref]\n\n\u003c/div\u003e\n\nPSUsing is a little PowerShell Module that provides an easy way to invoke a script block that can span different [__Input processing methods__][inputmethods] and automatically clean-up resources when completed.\n\n__Resource cleanup is enforced for the same scenarios as the ones detailed in [`clean` block][cleanblock]__:\n\n- When the pipeline execution finishes normally without terminating error.\n- When the pipeline execution is interrupted due to terminating error.\n- When the pipeline is halted by `Select-Object -First`.\n- When the pipeline is being stopped by \u003ckbd\u003eCTRL + C\u003c/kbd\u003e or `StopProcessing()`.\n\n## Documentation\n\nCheck out [__the docs__](./docs/en-US/Use-Object.md) for information about how to use this Module.\n\n## Installation\n\n### Gallery\n\nThe module is available through the [PowerShell Gallery][gallery_ref]:\n\n```powershell\nInstall-Module PSUsing -Scope CurrentUser\n```\n\n### Source\n\n```powershell\ngit clone 'https://github.com/santisq/PSUsing.git'\nSet-Location ./PSUsing\n./build.ps1\n```\n\n## Requirements\n\nCompatible with __Windows PowerShell v5.1__ and [__PowerShell 7+__][psgithub].\n\n## Usage\n\n### The most common pattern would be\n\n```powershell\nuse ($myobj = [DisposableObject]::new()) {\n   # do stuff with:\n   $myObj\n}\n```\n\n### The cmdlet can also process pipeline input, for example\n\n```powershell\n0..10 | use ($myobj = [DisposableObject]::new()) {\n   $myObj.DoStuff($_)\n}\n```\n\n### And can span different processing methods\n\n```powershell\n0..10 | use ($myobj = [DisposableObject]::new()) {\n   begin { 'begin' }\n   process { $myObj.DoStuff($_) }\n   end { 'end' }\n}\n```\n\n### A [`CancellationToken`][cancellation] is available for .NET methods that support it\n\n\u003e [!NOTE]\n\u003e The cancellation source is tied to the cmdlet's [`StopProcessing()` method][stopprocessing].\n\n```powershell\n# can CTRL+C out of this\nuse -sb {\n   param($token)\n   \n   [System.Threading.Tasks.Task]::Delay(-1, $token).Wait()\n}\n\n# can stop this\n$job = Start-Job {\n   use -sb {\n      param($token)\n\n      [System.Threading.Tasks.Task]::Delay(-1, $token).Wait()\n   }\n}\n\nStart-Sleep 1\n$job | Stop-Job\n```\n\n### The token can be cancelled on a timeout too\n\n```powershell\n# would throw a `TaskCanceledException` after 5 seconds\nuse -ct 5 -sb {\n   param($token)\n\n   [System.Threading.Tasks.Task]::Delay(-1, $token).GetAwaiter().GetResult()\n}\n```\n\n## Contributing\n\nContributions are welcome, if you wish to contribute, fork this repository and submit a pull request with the changes.\n\n[codecov_badge]: https://codecov.io/gh/santisq/PSUsing/branch/main/graph/badge.svg?token=b51IOhpLfQ\n[codecov_ref]: https://codecov.io/gh/santisq/PSUsing\n[build_badge]: https://github.com/santisq/PSUsing/actions/workflows/ci.yml/badge.svg\n[build_ref]: https://github.com/santisq/PSUsing/actions/workflows/ci.yml\n[gallery_badge]: https://img.shields.io/powershellgallery/dt/PSUsing?color=%23008FC7\n[gallery_ref]: https://www.powershellgallery.com/packages/PSUsing\n[license_badge]: https://img.shields.io/github/license/santisq/PSUsing\n[license_ref]: https://github.com/santisq/PSUsing/blob/main/LICENSE\n[cleanblock]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods#clean\n[csusing]: https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/statements/using\n[inputmethods]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_functions_advanced_methods#input-processing-methods\n[psgithub]: https://github.com/PowerShell/PowerShell\n[cancellation]: https://learn.microsoft.com/en-us/dotnet/api/system.threading.cancellationtoken\n[stopprocessing]: https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.cmdlet.stopprocessing\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantisq%2Fpsusing","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsantisq%2Fpsusing","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsantisq%2Fpsusing/lists"}