From ef3a3b903d54e1d8cb1d8863f6d0156ec5b14ffa Mon Sep 17 00:00:00 2001 From: Jeff Hicks Date: Sat, 21 Sep 2019 02:17:03 -0400 Subject: [PATCH] v1.5.0 --- Changelog.md | 11 +++ PSTypeExtensionTools.psd1 | Bin 8710 -> 8710 bytes PSTypeExtensionTools.psm1 | 30 +++++-- README.md | 5 +- docs/Add-PSTypeExtension.md | 44 +++++++--- docs/Export-PSTypeExtension.md | 2 +- docs/Get-PSType.md | 2 +- docs/Get-PSTypeExtension.md | 2 +- docs/Import-PSTypeExtension.md | 12 +-- docs/PSTypeExtensionTools.md | 2 +- docs/about_PSTypeExtensionTools.md | 4 +- en-us/PSTypeExtensionTools-help.xml | 100 +++++++++++++++++----- en-us/about_PSTypeExtensionTools.help.txt | 27 +++--- samples/README.md | 6 +- samples/eventlog-type.json | 12 ++- samples/fileinfo-extensions.json | 39 ++++++++- samples/measure-extensions.json | 16 ++++ 17 files changed, 239 insertions(+), 75 deletions(-) diff --git a/Changelog.md b/Changelog.md index 5917654..12dc710 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,16 @@ # Change Log for PSTypeExtensionTools +## v1.5.0 + ++ Added new parameter, `-IncludeDeserialized`, on `Add-PSTypeExtension` (Issue #14) ++ Modified `Import-PSTypeExtension` to allow piping files into the command. ++ Added alias `Type` to `-MemberType` parameter of `Add-PSTypeExtension` ++ Added alias `Name` to `-MemberName` parameter of `Add-PSTypeExtension` ++ Added online help links ++ Updated some of the sample json files to include deserialized type versions ++ Updated help documentation ++ Updated `README.md` + ## v1.4.0 + Modified manifest to require PowerShell 5.1 diff --git a/PSTypeExtensionTools.psd1 b/PSTypeExtensionTools.psd1 index efec37f59ab81d55fe80f7d6116594bc020a5f5b..9b3338e9791cf7c72acef30ad54808795f7c659f 100644 GIT binary patch delta 14 VcmZp3X>-|djgirG^L0jj1pq4<1uOsn delta 14 VcmZp3X>-|djgir0^L0jj1pq4(1uFmm diff --git a/PSTypeExtensionTools.psm1 b/PSTypeExtensionTools.psm1 index 2cbce19..c443de3 100644 --- a/PSTypeExtensionTools.psm1 +++ b/PSTypeExtensionTools.psm1 @@ -237,7 +237,7 @@ $(Get-Date) } } $memberdef.InnerText = $extension.value - $membertype.AppendChild($memberdef)| out-null + $membertype.AppendChild($memberdef) | out-null $member.AppendChild($membertype) | out-null } #foreach @@ -269,9 +269,11 @@ Function Import-PSTypeExtension { Param( [Parameter(Mandatory, ValueFromPipeline, + ValueFromPipelineByPropertyName, HelpMessage = "The name of the imported file. The extension must be .xml or .json")] [ValidatePattern("\.(xml|json)$")] - [ValidateScript( {Test-Path $(Convert-Path $_)})] + [ValidateScript( { Test-Path $(Convert-Path $_) })] + [alias("fullname")] [string]$Path ) @@ -318,19 +320,25 @@ Function Add-PSTypeExtension { [Alias('Set-PSTypeExtension')] Param( - [Parameter(Position = 0, Mandatory, + [Parameter( + Position = 0, + Mandatory, ValueFromPipeline, HelpMessage = "Enter the name of a type like system.io.fileinfo")] [string]$TypeName, [Parameter(Mandatory, HelpMessage = "The member type")] [ValidateSet("AliasProperty", "Noteproperty", "ScriptProperty", "ScriptMethod")] + [alias("Type")] [string]$MemberType, [Parameter(Mandatory, HelpMessage = "The name of your type extension")] [ValidateNotNullOrEmpty()] + [alias("Name")] [string]$MemberName, [Parameter(Mandatory, HelpMessage = "The value for your type extension. Remember to enclose scriptblocks in {} and use `$this")] [ValidateNotNullOrEmpty()] - [Object]$Value + [Object]$Value, + [Parameter(HelpMessage = "Create the extension in the deserialized version of the specified type including the original type.")] + [switch]$IncludeDeserialized ) Begin { @@ -339,9 +347,16 @@ Function Add-PSTypeExtension { } #begin Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $MemberType $Membername to $TypeName" #force overwrite of existing extensions $PSBoundParameters.Add("Force", $True) + if ($PSBoundParameters.ContainsKey("IncludeDeserialized")) { + [void]$PSBoundParameters.Remove("IncludeDeserialized") + $PSBoundParameters.Typename = "deserialized.$Typename" + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $MemberType $Membername to $($psboundparameters.TypeName)" + Update-TypeData @PSBoundParameters + $PSBoundParameters.Typename = $Typename + } + Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $MemberType $Membername to $($psboundparameters.TypeName)" Update-TypeData @PSBoundParameters } #process @@ -353,7 +368,6 @@ Function Add-PSTypeExtension { } #close Add-MyTypeExtension #Export the Samples folder location as a variable +$PSTypeSamples = Join-path $PSScriptRoot -ChildPath samples +Export-ModuleMember -Variable PSTypeSamples -$PSTypeSamples = "$PSScriptRoot\samples" - -Export-ModuleMember -Variable PSTypeSamples -function 'Get-PSTypeExtension', 'Get-PSType','Import-PSTypeExtension','Export-PSTypeExtension','Add-PSTypeExtension' -Alias 'Set-PSTypeExtension' \ No newline at end of file diff --git a/README.md b/README.md index 0087869..453f32d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ [![PSGallery Version](https://img.shields.io/powershellgallery/v/PSTypeExtensionTools.png?style=for-the-badge&logo=powershell&label=PowerShell%20Gallery)](https://www.powershellgallery.com/packages/PSTypeExtensionTools/) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/PSTypeExtensionTools.png?style=for-the-badge&label=Downloads)](https://www.powershellgallery.com/packages/PSTypeExtensionTools/) - 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](http://go.microsoft.com/fwlink/?LinkId=821805) or [Update-TypeData](http://go.microsoft.com/fwlink/?LinkId=821871). ## Release @@ -162,7 +161,7 @@ This project was first described at http://jdhitsolutions.com/blog/powershell/57 There is also an about topic you can read: ```powershell -help about_pstypeextensiontools +help about_PSTypeExtensionTools ``` -*last updated 18 February 2019* +Last Updated 2019-09-21 06:15:09Z UTC diff --git a/docs/Add-PSTypeExtension.md b/docs/Add-PSTypeExtension.md index 20641fd..ad01b75 100644 --- a/docs/Add-PSTypeExtension.md +++ b/docs/Add-PSTypeExtension.md @@ -1,7 +1,7 @@ --- external help file: PSTypeExtensionTools-help.xml Module Name: PSTypeExtensionTools -online version: +online version: http://bit.ly/30FkoJX schema: 2.0.0 --- @@ -13,9 +13,9 @@ Add a new type extension ## SYNTAX -```powershell -Add-PSTypeExtension [-TypeName] -MemberType -MemberName -Value [-WhatIf] - [-Confirm] [] +```yaml +Add-PSTypeExtension [-TypeName] -MemberType -MemberName -Value + [-IncludeDeserialized] [-WhatIf] [-Confirm] [] ``` ## DESCRIPTION @@ -43,6 +43,14 @@ True Define an script property called IsIPAddress which will return True if the string matches the pattern for an IP address. +### EXAMPLE 3 + +```powershell +PS C:\ Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType AliasProperty -MemberName Size -value Length -IncludeDeserialized +``` + +Create an alias called Size using the Length property on file objects. This expression will also create if for the deserialized version of the type so that you can use it with remoting results. + ## PARAMETERS ### -MemberName @@ -52,7 +60,7 @@ The name of your type extension. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: Name Required: True Position: Named @@ -68,8 +76,8 @@ The member type. You cannot use this command to define CodeMethods or CodeProper ```yaml Type: String Parameter Sets: (All) -Aliases: -Accepted values: AliasProperty, Noteproperty, ScriptProperty, ScriptMethod +Aliases: Type +Accepted values: AliasProperty, NoteProperty, ScriptProperty, ScriptMethod Required: True Position: Named @@ -80,7 +88,7 @@ Accept wildcard characters: False ### -TypeName -Enter the name of a type like system.io.fileinfo. +Enter the name of a type like System.IO.FileInfo. ```yaml Type: String @@ -101,7 +109,7 @@ The value for your type extension. Remember to enclose scriptblocks in {} and us ```yaml Type: Object Parameter Sets: (All) -Aliases: +Aliases: Required: True Position: Named @@ -142,9 +150,25 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -IncludeDeserialized + +Create the extension in the deserialized version of the specified type along with the specified type. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/docs/Export-PSTypeExtension.md b/docs/Export-PSTypeExtension.md index 981b642..f17f581 100644 --- a/docs/Export-PSTypeExtension.md +++ b/docs/Export-PSTypeExtension.md @@ -1,7 +1,7 @@ --- external help file: PSTypeExtensionTools-help.xml Module Name: PSTypeExtensionTools -online version: +online version: http://bit.ly/30FkCRj schema: 2.0.0 --- diff --git a/docs/Get-PSType.md b/docs/Get-PSType.md index 1864295..7aeee93 100644 --- a/docs/Get-PSType.md +++ b/docs/Get-PSType.md @@ -1,7 +1,7 @@ --- external help file: PSTypeExtensionTools-help.xml Module Name: PSTypeExtensionTools -online version: +online version: http://bit.ly/30FkNvX schema: 2.0.0 --- diff --git a/docs/Get-PSTypeExtension.md b/docs/Get-PSTypeExtension.md index cda809a..b60da75 100644 --- a/docs/Get-PSTypeExtension.md +++ b/docs/Get-PSTypeExtension.md @@ -1,7 +1,7 @@ --- external help file: PSTypeExtensionTools-help.xml Module Name: PSTypeExtensionTools -online version: +online version: http://bit.ly/30FkW2t schema: 2.0.0 --- diff --git a/docs/Import-PSTypeExtension.md b/docs/Import-PSTypeExtension.md index 36b705b..93a3c7b 100644 --- a/docs/Import-PSTypeExtension.md +++ b/docs/Import-PSTypeExtension.md @@ -1,7 +1,7 @@ --- external help file: PSTypeExtensionTools-help.xml Module Name: PSTypeExtensionTools -online version: +online version: http://bit.ly/30GCsUp schema: 2.0.0 --- @@ -37,7 +37,7 @@ Import definitions from a json file. PS C:\> dir c:\scripts\mytypes | Import-PSTypeExtension ``` -Import definitions from files in C:\Scripts\MyTypes. Presumably these are xml or json files created with Export-PSTypeExtension. +Import definitions from files in C:\Scripts\MyTypes. Presumably, these are xml or json files created with Export-PSTypeExtension. ## PARAMETERS @@ -48,12 +48,12 @@ The name of the imported file. The extension must be .xml or .json. ```yaml Type: String Parameter Sets: (All) -Aliases: +Aliases: fullname Required: True Position: 0 Default value: None -Accept pipeline input: True (ByValue) +Accept pipeline input: True (ByPropertyName, ByValue) Accept wildcard characters: False ``` @@ -91,7 +91,7 @@ Accept wildcard characters: False ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -110,3 +110,5 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell [Export-PSTypeExtension]() [Update-TypeData]() + +[Get-PSTypeExtension]() diff --git a/docs/PSTypeExtensionTools.md b/docs/PSTypeExtensionTools.md index b54cf22..7767204 100644 --- a/docs/PSTypeExtensionTools.md +++ b/docs/PSTypeExtensionTools.md @@ -1,7 +1,7 @@ --- Module Name: PSTypeExtensionTools Module Guid: f509035e-cb36-4d2f-b2c8-f4a60fb06d56 -Download Help Link: {{Please enter FwLink manually}} +Download Help Link: Help Version: 1.0.0.0 Locale: en-US --- diff --git a/docs/about_PSTypeExtensionTools.md b/docs/about_PSTypeExtensionTools.md index ab7de56..c84bf25 100644 --- a/docs/about_PSTypeExtensionTools.md +++ b/docs/about_PSTypeExtensionTools.md @@ -16,7 +16,7 @@ type name is. Once you have read help for the commands in this module you could run a PowerShell command like this: ```powershell -PS C:\> 123 | Get-PSType | +PS C:\> 123 | Get-PSType | Add-PSTypeExtension -MemberType ScriptProperty -MemberName SquareRoot ` -Value { [math]::Sqrt($this)} ``` @@ -70,7 +70,7 @@ 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) -``` +``` 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. diff --git a/en-us/PSTypeExtensionTools-help.xml b/en-us/PSTypeExtensionTools-help.xml index 1bde5fd..83fa1b3 100644 --- a/en-us/PSTypeExtensionTools-help.xml +++ b/en-us/PSTypeExtensionTools-help.xml @@ -18,7 +18,7 @@ TypeName - Enter the name of a type like system.io.fileinfo. + Enter the name of a type like System.IO.FileInfo. String @@ -27,7 +27,7 @@ None - + MemberName The name of your type extension. @@ -39,14 +39,14 @@ None - + MemberType The member type. You cannot use this command to define CodeMethods or CodeProperties. AliasProperty - Noteproperty + NoteProperty ScriptProperty ScriptMethod @@ -91,10 +91,21 @@ False + + IncludeDeserialized + + Create the extension in the deserialized version of the specified type along with the specified type. + + + SwitchParameter + + + False + - + MemberName The name of your type extension. @@ -106,7 +117,7 @@ None - + MemberType The member type. You cannot use this command to define CodeMethods or CodeProperties. @@ -121,7 +132,7 @@ TypeName - Enter the name of a type like system.io.fileinfo. + Enter the name of a type like System.IO.FileInfo. String @@ -166,6 +177,18 @@ False + + IncludeDeserialized + + Create the extension in the deserialized version of the specified type along with the specified type. + + SwitchParameter + + SwitchParameter + + + False + @@ -194,14 +217,14 @@ - EXAMPLE 1 + -------------------------- EXAMPLE 1 -------------------------- PS C:\> Add-PSTypeExtension -TypeName system.string -MemberType AliasProperty -MemberName Size -Value Length Define an alias property called Size for the Length property of the String type. - EXAMPLE 2 + -------------------------- EXAMPLE 2 -------------------------- PS C:\> Add-PSTypeExtension -TypeName system.string -MemberType ScriptMethod -MemberName IsIPAddress -value {$this -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$"} PS C:\> $s = "10.4.7.10" PS C:\> $s.IsIPAddress() @@ -210,8 +233,19 @@ True Define an script property called IsIPAddress which will return True if the string matches the pattern for an IP address. + + -------------------------- EXAMPLE 3 -------------------------- + PS C:\ Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType AliasProperty -MemberName Size -value Length -IncludeDeserialized + + Create an alias called Size using the Length property on file objects. This expression will also create if for the deserialized version of the type so that you can use it with remoting results. + + + + Online Version: + http://bit.ly/30FkoJX + Get-PSTypeExtension @@ -443,21 +477,21 @@ True - EXAMPLE 1 + -------------------------- EXAMPLE 1 -------------------------- PS C:\> Export-PSTypeExtension -TypeName system.string -Path c:\work\mystringtypes.json -MemberName Size,IsIPAddress Export selected type extensions for System.String to a json file. - EXAMPLE 2 + -------------------------- EXAMPLE 2 -------------------------- PS C:\> Get-PSTypeExtension system.string | Export-PSTypeExtension -path c:\work\stringtypes.xml Get all type extensions for System.String and export to an xml file. - EXAMPLE 3 + -------------------------- EXAMPLE 3 -------------------------- PS C:\> Get-PSTypeExtension system.string -members "IsIpAddress","Size","Randomize" | Export-PSTypeExtension -path c:\work\mystring.type.ps1xml Export the selected members to a properly formatted ps1xml file. @@ -465,6 +499,10 @@ True + + Online Version: + http://bit.ly/30FkCRj + Import-PSTypeExtension @@ -545,7 +583,7 @@ True - EXAMPLE 1 + -------------------------- EXAMPLE 1 -------------------------- PS C:\>123 | Get-PSType System.Int32 @@ -553,7 +591,7 @@ System.Int32 - EXAMPLE 2 + -------------------------- EXAMPLE 2 -------------------------- PS C:\>"apple" | Get-PSType | Get-PSTypeExtension TypeName: System.String @@ -567,7 +605,7 @@ IsIPAddress ScriptMethod $this -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$" - EXAMPLE 3 + -------------------------- EXAMPLE 3 -------------------------- PS C:\> get-vm win10 | get-pstype | Add-PSTypeExtension -MemberType ScriptProperty -MemberName VMAge -Value {(Get-Date)- $this.Creationtime} PS C:\> get-vm | sort VMAge -descending | select Name,Creationtime,VMAge @@ -587,6 +625,10 @@ Win10Ent 10/16/2017 9:30:46 AM 25.00:49:58.1206825 + + Online Version: + http://bit.ly/30FkNvX + Get-PSTypeExtension @@ -695,7 +737,7 @@ Win10Ent 10/16/2017 9:30:46 AM 25.00:49:58.1206825 - EXAMPLE 1 + -------------------------- EXAMPLE 1 -------------------------- PS C:\> Get-PSTypeExtension system.string TypeName: System.String @@ -712,7 +754,7 @@ Randomize ScriptMethod ($this.ToCharArray() | get-random -Count $this.length - EXAMPLE 2 + -------------------------- EXAMPLE 2 -------------------------- PS C:\> Get-PSTypeExtension system.string -members size TypeName: System.String @@ -725,7 +767,7 @@ Size AliasProperty Length - EXAMPLE 3 + -------------------------- EXAMPLE 3 -------------------------- PS C:\> get-process | get-pstype | Get-PSTypeExtension @@ -754,6 +796,10 @@ __NounName Noteproperty Process + + Online Version: + http://bit.ly/30FkW2t + Get-TypeData @@ -775,7 +821,7 @@ __NounName Noteproperty Process Import-PSTypeExtension - + Path The name of the imported file. The extension must be .xml or .json. @@ -812,7 +858,7 @@ __NounName Noteproperty Process - + Path The name of the imported file. The extension must be .xml or .json. @@ -876,21 +922,25 @@ __NounName Noteproperty Process - EXAMPLE 1 + -------------------------- EXAMPLE 1 -------------------------- PS C:\> Import-PSTypeExtension -Path C:\work\stringtypes.json Import definitions from a json file. - EXAMPLE 2 + -------------------------- EXAMPLE 2 -------------------------- PS C:\> dir c:\scripts\mytypes | Import-PSTypeExtension - Import definitions from files in C:\Scripts\MyTypes. Presumably these are xml or json files created with Export-PSTypeExtension. + Import definitions from files in C:\Scripts\MyTypes. Presumably, these are xml or json files created with Export-PSTypeExtension. + + Online Version: + http://bit.ly/30GCsUp + Export-PSTypeExtension @@ -899,6 +949,10 @@ __NounName Noteproperty Process Update-TypeData + + Get-PSTypeExtension + + \ No newline at end of file diff --git a/en-us/about_PSTypeExtensionTools.help.txt b/en-us/about_PSTypeExtensionTools.help.txt index 552658a..794db57 100644 --- a/en-us/about_PSTypeExtensionTools.help.txt +++ b/en-us/about_PSTypeExtensionTools.help.txt @@ -4,15 +4,15 @@ 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 simplify the + Get-TypeData or Update-TypeData. The commands in this module simplify the process of finding, creating, exporting and importing type extensions. LONG DESCRIPTION - Let's say you want to update a number object, but you have no idea what the - type name is. Once you have read help for the commands in this module you + Let's say you want to update a number object, but you have no idea what the + type name is. Once you have read help for the commands in this module you could run a PowerShell command like this: - PS C:\> 123 | Get-PSType | + PS C:\> 123 | Get-PSType | Add-PSTypeExtension -MemberType ScriptProperty -MemberName SquareRoot ` -Value { [math]::Sqrt($this)} @@ -34,11 +34,11 @@ LONG DESCRIPTION PS C:\> $x = 38 PS C:\> $x | select * - + SquareRoot Squared Cubed Value ---------- ------- ----- ----- 6.16441400296898 1444 54872 38 - + PS C:\> $x.GetPercent(50) 76 PS C:\> $x.GetPercent(100) @@ -50,9 +50,9 @@ LONG DESCRIPTION to see all extensions or selected ones by member name. PS C:\> Get-PSTypeExtension system.int32 - + TypeName: System.Int32 - + Name Type Value ---- ---- ----- SquareRoot ScriptProperty [math]::Sqrt($this) @@ -67,7 +67,7 @@ LONG DESCRIPTION helpful if you are extending a type that already has type extensions from PowerShell. - PS C:\> Get-PSTypeExtension system.int32 -all | + PS C:\> Get-PSTypeExtension system.int32 -all | Export-PSTypeExtension -TypeName system.int32 -Path c:\work\int32-types.json In your PowerShell profile script you can then re-import the type extension @@ -80,10 +80,10 @@ LONG DESCRIPTION dir c:\scripts\mytypes | Import-PSTypeExtension A number of sample files with type extensions can be found in this modules - Samples folder or in the GitHub repository at + Samples folder or in the GitHub repository at https://github.com/jdhitsolutions/PSTypeExtensionTools/tree/master/samples. - When you have imported the module you can access the samples folder using the + When you have imported the module you can access the samples folder using the $PSTypeSamples variable. Import-PSTypeExtension $PSTypeSamples\measure-extensions.json @@ -115,11 +115,10 @@ SEE ALSO Get-PSTypeExtension Import-PSTypeExtension Update-TypeData - + This project was first described at http://jdhitsolutions.com/blog/powershell/5777/a-powershell-module-for-your-type-extensions KEYWORDS - typedata + typedata typeextension - diff --git a/samples/README.md b/samples/README.md index 2aab513..d93f72d 100644 --- a/samples/README.md +++ b/samples/README.md @@ -1,7 +1,7 @@ -# Samples +# PSTypeExtension Samples These files are intended to be used with [Import-PSTypeExtension](../docs/Import-PSTypeExtension.md). Save the file locally and run the import command. You must specify the full file name with extension so the function knows how to import the data. Importing *will* overwrite any existing type members with the same name. The new type members will only last for the duration of your PowerShell session. If you always want a set of type extensions, put the `Import-PSTypeExtension` command into your PowerShell profile script. -``` -dir c:\scripts\myextensions\*.json | foreach { $_ |Import-PSTypeExtension} +```powershell +dir c:\scripts\myextensions\*.json | Import-PSTypeExtension ``` diff --git a/samples/eventlog-type.json b/samples/eventlog-type.json index d7eb16a..ae08a92 100644 --- a/samples/eventlog-type.json +++ b/samples/eventlog-type.json @@ -1,6 +1,14 @@ -{ +[ + { "MemberType": "ScriptProperty", "MemberName": "Computername", "Value": "if ($this.machinename -eq \u0027.\u0027) {$env:computername} else {$this.machinename}", "TypeName": "System.Diagnostics.EventLog" -} +}, + { + "MemberType": "ScriptProperty", + "MemberName": "Computername", + "Value": "if ($this.machinename -eq \u0027.\u0027) {$env:computername} else {$this.machinename}", + "TypeName": "Deserialized.System.Diagnostics.EventLog" + } +] diff --git a/samples/fileinfo-extensions.json b/samples/fileinfo-extensions.json index 03153dd..c777168 100644 --- a/samples/fileinfo-extensions.json +++ b/samples/fileinfo-extensions.json @@ -1,4 +1,5 @@ -[{ +[ + { "MemberType": "AliasProperty", "MemberName": "Size", "Value": "Length", @@ -39,5 +40,41 @@ "MemberName": "Created", "Value": "CreationTime", "TypeName": "System.IO.FileInfo" + }, + { + "MemberType": "AliasProperty", + "MemberName": "Size", + "Value": "Length", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "SizeKB", + "Value": "[math]::Round($this.length/1KB,2)", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "SizeMB", + "Value": "[math]::Round($this.length/1MB,2)", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "SizeGB", + "Value": "[math]::Round($this.length/1GB,2)", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "Age", + "Value": "'{0:dd\\.hh\\:mm\\:ss}' -f ((Get-Date) - $this.LastWriteTime)", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "AliasProperty", + "MemberName": "Modified", + "Value": "LastWriteTime", + "TypeName": "Deserialized.System.IO.FileInfo" + }, { + "MemberType": "AliasProperty", + "MemberName": "Created", + "Value": "CreationTime", + "TypeName": "Deserialized.System.IO.FileInfo" } ] \ No newline at end of file diff --git a/samples/measure-extensions.json b/samples/measure-extensions.json index dcd1a6d..34b612d 100644 --- a/samples/measure-extensions.json +++ b/samples/measure-extensions.json @@ -16,5 +16,21 @@ "MemberName": "SumGB", "Value": "[math]::Round($this.sum/1gb,4)", "TypeName": "Microsoft.PowerShell.Commands.GenericMeasureInfo" + }, + { + "MemberType": "ScriptProperty", + "MemberName": "SumKB", + "Value": "[math]::Round($this.sum/1kb,4)", + "TypeName": "Deserialized.Microsoft.PowerShell.Commands.GenericMeasureInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "SumMB", + "Value": "[math]::Round($this.sum/1mb,4)", + "TypeName": "Deserialized.Microsoft.PowerShell.Commands.GenericMeasureInfo" + }, { + "MemberType": "ScriptProperty", + "MemberName": "SumGB", + "Value": "[math]::Round($this.sum/1gb,4)", + "TypeName": "Deserialized.Microsoft.PowerShell.Commands.GenericMeasureInfo" } ]