Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ConvertTo-Hashtable {
- [CmdletBinding()][OutputType([hashtable])]
- Param (
- [Parameter(Mandatory, ValueFromPipeline)][System.Object]$InputObject
- )
- BEGIN {
- [boolean]$IgnoreProcess = $false
- [System.Collections.Generic.List``1[System.Object]]$List = @()
- If ($PSBoundParameters.ContainsKey('InputObject')) {
- [void]$List.AddRange(@($InputObject))
- $IgnoreProcess = $true
- }
- $ProcessOneObject = {
- $Object = $List[0]
- [void]$List.RemoveAt(0)
- #region Place code to handle one object in this region
- $Object.PSObject.Properties | % -Begin { $h = @{ } } -Process { [void]$h.Add($_.Name, $_.Value) } -End { $h }
- #endregion
- }
- }
- PROCESS {
- if ($IgnoreProcess) { return }
- [void]$List.Add($InputObject)
- . $ProcessOneObject
- }
- END {
- try {
- while ($List.Count -gt 0) { . $ProcessOneObject }
- } catch {
- throw
- } finally {
- trap { continue }
- $ErrorActionPreference = 'SilentlyContinue'
- #region Cleanup code
- #endregion
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement