From a05b24f04f78f1c8c70d798e5d99a0cc345cbf9f Mon Sep 17 00:00:00 2001 From: Jeff Hicks Date: Fri, 28 Sep 2018 09:47:40 -0400 Subject: [PATCH] sample updates --- Changelog.txt | 5 +++++ PSTypeExtensionTools.psd1 | Bin 8652 -> 8652 bytes PSTypeExtensionTools.psm1 | 22 ++++++++++++++++------ docs/about_PSTypeExtensionTools.md | 23 ++++++++++++----------- samples/datetime-extensions.json | 6 ++++++ 5 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 samples/datetime-extensions.json diff --git a/Changelog.txt b/Changelog.txt index 5dce2a4..5c40161 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -1,5 +1,10 @@ # Changelog for PSTypeExtensionTools +## v1.1.0 +- Fixed Import-PSTypeExtension bug piping in json/xml files (Issue #13) +- Updated About help documentation +- Modified pipeline processing in Get-PSTypeExtension (Issue #12) + ## v1.0.0 - Modified Export-PSTypeExtension to export to a ps1xml file (Issue #11) - release to the PowerShell Gallery diff --git a/PSTypeExtensionTools.psd1 b/PSTypeExtensionTools.psd1 index 2456f443a16402026de6e470afa6d59ef9a477e2..a6c6851cc0d9b3f709ee80ad160b79e5825b2bd8 100644 GIT binary patch delta 14 WcmX@(e8zdhHAY6m&DR;f$^!s1kOp@E delta 14 WcmX@(e8zdhHAY5*&DR;f$^!s1iUxK7 diff --git a/PSTypeExtensionTools.psm1 b/PSTypeExtensionTools.psm1 index 594319b..5f12b1f 100644 --- a/PSTypeExtensionTools.psm1 +++ b/PSTypeExtensionTools.psm1 @@ -26,10 +26,16 @@ Function Get-PSTypeExtension { Begin { Write-Verbose "Starting: $($MyInvocation.Mycommand)" - } + $typedata=@() + } #begin Process { - $typedata = Get-TypeData -TypeName $typename + Write-Verbose "Analyzing $typename" + $typedata += Get-TypeData -TypeName $typename + + } #process + End { + $typedata = $typedata | Select-Object -Unique if ($typedata) { if (-Not $Members) { @@ -120,8 +126,6 @@ Function Get-PSTypeExtension { else { Write-Warning "Failed to find any type extensions for [$Typename]." } - } - End { Write-Verbose "Ending: $($MyInvocation.Mycommand)" } @@ -272,7 +276,10 @@ Function Import-PSTypeExtension { [string]$Path ) + Begin { Write-Verbose "Starting: $($myInvocation.mycommand)" + } + Process { Write-Verbose "Importing file $(Convert-path $Path)" if ($path -match "\.xml$") { #xml format seems to add an extra entry @@ -300,8 +307,11 @@ Function Import-PSTypeExtension { Update-TypeData -TypeName $item.Typename -MemberType $item.MemberType -MemberName $item.MemberName -value $value -force } } #foreach - - Write-Verbose "Ending: $($myInvocation.mycommand)" + } + End { + Write-Verbose "Ending: $($myInvocation.mycommand)" + } + } #end Import-PSTypeExtension Function Add-PSTypeExtension { diff --git a/docs/about_PSTypeExtensionTools.md b/docs/about_PSTypeExtensionTools.md index a8178e0..f427a50 100644 --- a/docs/about_PSTypeExtensionTools.md +++ b/docs/about_PSTypeExtensionTools.md @@ -1,10 +1,10 @@ -# PSTypeExtensionTools +# PSTypeExtensionTools ## about_PSTypeExtensionTools # SHORT DESCRIPTION This PowerShell module contains commands that make it easier to work with type extensions. Many of these commands are wrappers for built-in tools like -Get-TypeData or Update-TypeData. The commands in this module simplfy the +`Get-TypeData` or `Update-TypeData`. The commands in this module simplify the process of finding, creating, exporting and importing type extensions. # LONG DESCRIPTION @@ -45,7 +45,7 @@ PS C:\> $x.GetPercent(100) PS C:\> $x.GetPercent(110,4) 34.5455 ``` -To see what has been defined you can use Get-PSTypeExtension. You can choose to see all extensions or selected ones by member name. +To see what has been defined you can use `Get-PSTypeExtension`. You can choose to see all extensions or selected ones by member name. ``` PS C:\> Get-PSTypeExtension system.int32 @@ -57,8 +57,8 @@ SquareRoot ScriptProperty [math]::Sqrt($this) Squared ScriptProperty $this*$this Cubed ScriptProperty [math]::Pow($this,3) Value ScriptProperty $this -GetPercent ScriptMethod Param([int32]$Total,[int32]$Round=2) [math]::Round(($this/$total)*100,$round) -``` +GetPercent ScriptMethod Param([int32]$Total,[int32]$Round=2) [math]::Round(($this/$total)*100,$round) +``` If you always want these extensions you would have to put the commands into your PowerShell profile script. Or you can export the extensions to a json or xml file. You can either export all members or selected ones which is helpful if you are extending a type that already has type extensions from PowerShell. ``` PS C:\> Get-PSTypeExtension system.int32 -all | @@ -88,17 +88,17 @@ Remember to use $this to reference the object and NOT $_. Remember to enclose scriptblocks in {}. # SEE ALSO -Add-PSTypeExtension +[Add-PSTypeExtension](./Add-PSTypeExtension.md) -Export-PSTypeExtension +[Export-PSTypeExtension](./Export-PSTypeExtension.md) -Get-PSType +[Get-PSType](./Get-PSType.md) -Get-PSTypeExtension +[Get-PSTypeExtension](./Get-PSTypeExtension.md) -Import-PSTypeExtension +[Import-PSTypeExtension](./Import-PSTypeExtension.md) -Update-TypeData +[Update-TypeData](./Update-TypeData.md) This project was first described at http://jdhitsolutions.com/blog/powershell/5777/a-powershell-module-for-your-type-extensions @@ -106,3 +106,4 @@ This project was first described at http://jdhitsolutions.com/blog/powershell/57 # KEYWORDS typedata typeextension +] \ No newline at end of file diff --git a/samples/datetime-extensions.json b/samples/datetime-extensions.json new file mode 100644 index 0000000..daebb7a --- /dev/null +++ b/samples/datetime-extensions.json @@ -0,0 +1,6 @@ +{ + "MemberType": "ScriptMethod", + "MemberName": "ConvertCulture", + "Value": "Param ([string]$culture)\r\n\r\n\"{0:$([cultureinfo]::GetCultureInfo(\"$culture\").DateTimeFormat.fulldatetimepattern)}\" -f $this", + "TypeName": "System.DateTime" +}