Skip to content

Commit

Permalink
v1.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Mar 8, 2021
1 parent 6020d83 commit 7db8739
Show file tree
Hide file tree
Showing 10 changed files with 891 additions and 243 deletions.
9 changes: 4 additions & 5 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Change Log for PSTypeExtensionTools

## TODO

+ `Export-PSTypeExtension` to allow appending to a file and to be able to store different types in the same file.([Issue #16](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/16))

## v1.6.0

+ Re-organized module structure.
+ Added `New-PSPropertySet` ([Issue #15](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/15))
+ Added command `New-PSPropertySet`to create a ps1xml file that defines a custom property set. ([Issue #15](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/15))
+ Modified `Get-PSTypeExtension` to hide `CodeProperty` values by defaults. ([Issue #17](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/1))
+ Modified `Get-PSTypeExtension` to display results sorted by member type and name.

## v1.5.1


+ Fixed error in exporting aliases.
+ Updated license file.
+ Very minor help corrections.
Expand Down
55 changes: 48 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,11 @@ In your PowerShell profile scrip,t you can then re-import the type extension def
Import-PSTypeExtension -Path C:\work\int32-types.json
```

## Create ps1xml Files

The export command makes it easy to construct a ps1xml file. All you need to do is provide the type name and the extensions you want to export, and it will create a properly formatted ps1xml file that you can import into a session with `Update-TypeData` or distribute with a module. No more clunky XML copying, pasting, and hoping for the best.

## PSTypeExtensionTools Cmdlets

### [Add-PSTypeExtension](docs/Add-PSTypeExtension.md)

Add a new type extension such as an Alias or ScriptProperty.
Add a new type extension such as an `Alias` or `ScriptProperty`.

### [Export-PSTypeExtension](docs/Export-PSTypeExtension.md)

Expand All @@ -112,7 +108,52 @@ Import type extension definitions from a JSON file or XML.

### [New-PSPropertySet](docs/New-PSPropertySet.md)

TBD
In addition to custom properties, PowerShell also has the idea of a _propertyset_. This allows you to reference a group of properties with a single name.

Let's say you have loaded the sample fileinfo type extensions from this module.

```powershell
PS C:\> Import-PSTypeExtension -Path $PSTypeSamples\fileinfo-extensions.json
```powershell
You could write a command like this:
```powershell
dir c:\work -file | Select-Object Name,Size,LastWriteTime,Age
```

Or you could create a custom property set. These have to be defined in `ps1xml` files. The `New-PSPropertySet` simplifies this process.

```powershell
New-PSPropertySet -Typename System.IO.FileInfo -Name FileAge -Properties Name,Size,LastWriteTime,Age -FilePath d:\temp\Fileinfo.types.ps1xml
```

I've included the file in the Samples folder.

```powershell
PS C:\> Update-TypeData $PSTypeSamples\fileinfo.types.ps1xml
PS C:\> dir c:\work -file | Select-Object fileage
Name Size LastWriteTime Age
---- ---- - ----------- ---
a.dat 42 2/12/2021 5:36:55 PM 23.17:27:21
a.txt 14346 12/31/2020 9:10:15 AM 67.01:54:00
a.xml 171394 12/31/2020 12:15:44 PM 66.22:48:32
aa.ps1 28866 12/31/2020 9:13:16 AM 67.01:51:00
aa.txt 28866 12/31/2020 9:11:18 AM 67.01:52:58
about.json 16455 2/27/2021 10:11:03 AM 09.00:53:12
about_ADReportingTools 1688 3/4/2021 7:37:01 PM 03.15:27:14
b.csv 1273 11/13/2020 12:11:35 PM 114.22:52:40
...
```

If your property set is using custom properties, you need to load them into your PowerShell session before you can use the property set.

## Create ps1xml Files

The export command makes it easy to construct a ps1xml file. All you need to do is provide the type name and the extensions you want to export, and it will create a properly formatted ps1xml file that you can import into a session with `Update-TypeData` or distribute with a module. No more clunky XML copying, pasting, and hoping for the best.

Well, there is one reason you still might need to do some copying and pasting. Technically, you can define all custom properties, including property sets, in a single .ps1xml file. However, I don't have a simple command to export everything for a single type to a single file. For now, you can create a `<typename>.types.ps1xml` file for your custom extensions. Then manually merge the `Members` section from your property set .ps1xml file. This is only necessary if you have custom extensions **and** one or more property sets defined for a given type.

## I Want to Try

Expand Down Expand Up @@ -167,4 +208,4 @@ There is also an about topic you can read:
help about_PSTypeExtensionTools
```

Last Updated 2019-09-21 06:15:09Z UTC
Last Updated 2021-03-08 21:19:40Z
58 changes: 53 additions & 5 deletions docs/Get-PSTypeExtension.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ Get selected type extensions.
## SYNTAX

```yaml
Get-PSTypeExtension [-TypeName] <String> [-Members <String[]>] [<CommonParameters>]
Get-PSTypeExtension [-TypeName] <String> [-Members <String[]>] [-CodeProperty] [<CommonParameters>]
```

## DESCRIPTION

Use this command to list defined type extensions. You can either select individual ones or all of them. Do not specify any members to retrieve all of them. This command is very similar to Get-TypeData, except that it makes it easier to see the extension value.

By default, CodeProperty members are not displayed because they can't be exported.

## EXAMPLES

### EXAMPLE 1
Expand Down Expand Up @@ -58,7 +60,7 @@ Get the Size type extension for System.String.
### EXAMPLE 3

```powershell
PS C:\> get-process | get-pstype | Get-PSTypeExtension
PS C:\> Get-Process | Get-PSType | Get-PSTypeExtension
TypeName: System.Diagnostics.Process
Expand All @@ -84,6 +86,32 @@ __NounName Noteproperty Process

Discover type extensions for a given type of object.

### Example 4

```powershell
PS C:\> Get-PSTypeExtension system.io.fileinfo -CodeProperty |
Select-Object membername,membertype
MemberName MemberType
---------- ----------
Size AliasProperty
Modified AliasProperty
Created AliasProperty
Mode CodeProperty
ModeWithoutHardLink CodeProperty
Target CodeProperty
LinkType CodeProperty
NameString CodeProperty
LengthString CodeProperty
LastWriteTimeString CodeProperty
VersionInfo ScriptProperty
BaseName ScriptProperty
SizeKB ScriptProperty
SizeMB ScriptProperty
```

Display all extensions, including CodeProperty, and display the member name and type.

## PARAMETERS

### -Members
Expand All @@ -104,7 +132,7 @@ Accept wildcard characters: False
### -TypeName
Enter the name of type like System.IO.FileInfo.
Enter the name of a type like System.IO.FileInfo.
```yaml
Type: String
Expand All @@ -118,17 +146,33 @@ Accept pipeline input: True (ByPropertyName, ByValue)
Accept wildcard characters: False
```
### -CodeProperty
Show CodeProperty custom properties
```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
### System.String
## OUTPUTS
### System.Object
### PSTypeExtension
## NOTES
Expand All @@ -137,4 +181,8 @@ http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[Get-PSType](Get-PSType.md)
[Export-PSTypeExtension](Export-PSTypeExtension.md)
[Get-TypeData]()
14 changes: 8 additions & 6 deletions docs/New-PSPropertySet.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: https://github.com/jdhitsolutions/PSTypeExtensionTools/blob/master/docs/New-PSPropertySet.md
schema: 2.0.0
---

Expand Down Expand Up @@ -31,15 +31,15 @@ PowerShell has a concept of property sets. A property set allows you to referenc

Use Update-TypeData to append the file. If you import your file more than once in the same session, you might see a warning about existing property names. Existing entries won't be overwritten.

Property set updates are not persistant. You will need to import your ps1xml, ideally in your PowerShell profile script.
Property set updates are not persistent. You will need to import your ps1xml, ideally in your PowerShell profile script.

## EXAMPLES

### Example 1

```powershell
PS C:\> New-PSPropertySet -typename System.IO.FileInfo -name info -properties Fullname,IsReadOnly,CreationTime,LastWriteTime -filepath c:\work\myfileinfo.type.ps1xml
PS C:\> Update-TypeData C:\work\myfileinfo.type.ps1xml
PS C:\> New-PSPropertySet -typename System.IO.FileInfo -name info -properties Fullname,IsReadOnly,CreationTime,LastWriteTime -filepath c:\work\myfileinfo.types.ps1xml
PS C:\> Update-TypeData C:\work\myfileinfo.types.ps1xml
PS C:\> dir c:\work -file | select info
FullName IsReadOnly CreationTime LastWriteTime
Expand Down Expand Up @@ -92,7 +92,7 @@ Accept wildcard characters: False
### -FilePath
Enter the name of the .ps1xml file to create.
Enter the name of the .ps1xml file to create. It must have a .ps1xml file extension and ideally should take the format <typename>.types.ps1xml.
```yaml
Type: String
Expand Down Expand Up @@ -140,7 +140,7 @@ Accept wildcard characters: False
### -Properties
Enter the existing property names or aliases to belong to this property set.
Enter the existing property names or aliases to belong to this property set. If using aliases, they must be defined in your PowerShell session before you can use the custom property set.
```yaml
Type: String[]
Expand Down Expand Up @@ -207,3 +207,5 @@ http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[Update-TypeData]()
[Add-PSTypeExtension](Add-PSTypeExtension.md)
4 changes: 2 additions & 2 deletions docs/about_PSTypeExtensionTools.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ PS C:\> $x.SquareRoot
11.0905365064094
```

Once you know the type name you can add other type extensions.
Once you know the type name, you can add other type extensions.

```powershell
Add-PSTypeExtension -TypeName system.int32 -MemberType ScriptProperty -MemberName Squared -value { $this*$this}
Expand Down Expand Up @@ -90,7 +90,7 @@ You can also import a directory of type extensions with a single command.
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 https://github.com/jdhitsolutions/PSTypeExtensionTools/tree/master/samples. When you have imported the module you can access the samples folder using the $PSTypeSamples variable.
A number of sample files with type extensions can be found in this module's Samples folder or 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 `$PSTypeSamples` variable.

```powershell
Import-PSTypeExtension $PSTypeSamples\measure-extensions.json
Expand Down
Loading

0 comments on commit 7db8739

Please sign in to comment.