Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Sep 21, 2019
1 parent 792e384 commit ef3a3b9
Show file tree
Hide file tree
Showing 17 changed files with 239 additions and 75 deletions.
11 changes: 11 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Binary file modified PSTypeExtensionTools.psd1
Binary file not shown.
30 changes: 22 additions & 8 deletions PSTypeExtensionTools.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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 {
Expand All @@ -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

Expand All @@ -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'
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
44 changes: 34 additions & 10 deletions docs/Add-PSTypeExtension.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand All @@ -13,9 +13,9 @@ Add a new type extension

## SYNTAX

```powershell
Add-PSTypeExtension [-TypeName] <String> -MemberType <String> -MemberName <String> -Value <Object> [-WhatIf]
[-Confirm] [<CommonParameters>]
```yaml
Add-PSTypeExtension [-TypeName] <String> -MemberType <String> -MemberName <String> -Value <Object>
[-IncludeDeserialized] [-WhatIf] [-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -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
Expand All @@ -52,7 +60,7 @@ The name of your type extension.
```yaml
Type: String
Parameter Sets: (All)
Aliases:
Aliases: Name

Required: True
Position: Named
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/Export-PSTypeExtension.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
2 changes: 1 addition & 1 deletion docs/Get-PSType.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
2 changes: 1 addition & 1 deletion docs/Get-PSTypeExtension.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down
12 changes: 7 additions & 5 deletions docs/Import-PSTypeExtension.md
Original file line number Diff line number Diff line change
@@ -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
---

Expand Down Expand Up @@ -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

Expand All @@ -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
```
Expand Down Expand Up @@ -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
Expand All @@ -110,3 +110,5 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
[Export-PSTypeExtension]()
[Update-TypeData]()
[Get-PSTypeExtension]()
2 changes: 1 addition & 1 deletion docs/PSTypeExtensionTools.md
Original file line number Diff line number Diff line change
@@ -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
---
Expand Down
4 changes: 2 additions & 2 deletions docs/about_PSTypeExtensionTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
```
Expand Down Expand Up @@ -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.

Expand Down
Loading

0 comments on commit ef3a3b9

Please sign in to comment.