diff --git a/Changelog.md b/Changelog.md index 917ac56..fb19b24 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,145 +1,151 @@ # Change Log for PSTypeExtensionTools +## v1.10.0 + +- Code cleanup and re-formatting. +- Help updates. +- Updated `README.md`. + ## v1.9.0 -+ Fixed bug in `New-PSPropertySet` that failed to recognize a custom type. ([Issue #21](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/21)) -+ Re-organized module layout. -+ Help updates. -+ Updated `README.md`. +- Fixed bug in `New-PSPropertySet` that failed to recognize a custom type. ([Issue #21](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/21)) +- Re-organized module layout. +- Help updates. +- Updated `README.md`. ## v1.8.0 -+ Fixed bugs in `Get-PSTypeExtension` and `Export-PSTypeExtension` where I needed to let the user force recognizing a type name. ([Issue #20](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/20)) -+ Help updates. -+ Updated `README.md`. +- Fixed bugs in `Get-PSTypeExtension` and `Export-PSTypeExtension` where I needed to let the user force recognizing a type name. ([Issue #20](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/20)) +- Help updates. +- Updated `README.md`. ## v1.7.1 -+ Fixed bug in `New-PSPropertySet` that failed to correct typename case. ([Issue #19](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/19)) -+ Updated online help link for `New-PSPropertySet`. -+ Added sample file `process.types.ps1xml`. -+ Updated `README.md`. +- Fixed bug in `New-PSPropertySet` that failed to correct typename case. ([Issue #19](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/19)) +- Updated online help link for `New-PSPropertySet`. +- Added sample file `process.types.ps1xml`. +- Updated `README.md`. ## v1.7.0 -+ Added `services.types.ps1xml` to samples folder. -+ Updated `README.md`. -+ Updates `README.md` in Samples folder. -+ Changed statements using `Out-Null` to use `[void]`. -+ Modified `Export-PSTypeExtension` to support appending in a very specific use-case. ([Issue #16](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/16)) -+ Added a private function, `_convertTypeName` to convert typename values to properly cased names. -+ Modified `Export-PSTypeExtension` to add a `-Passthru` parameter. ([Issue #18](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/18)) -+ Updated help. +- Added `services.types.ps1xml` to samples folder. +- Updated `README.md`. +- Updates `README.md` in Samples folder. +- Changed statements using `Out-Null` to use `[void]`. +- Modified `Export-PSTypeExtension` to support appending in a very specific use-case. ([Issue #16](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/16)) +- Added a private function, `_convertTypeName` to convert typename values to properly cased names. +- Modified `Export-PSTypeExtension` to add a `-Passthru` parameter. ([Issue #18](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/18)) +- Updated help. ## v1.6.0 -+ Re-organized module structure. -+ 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. +- Re-organized module structure. +- 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. +- Fixed error in exporting aliases. +- Updated license file. +- Very minor help corrections. ## v1.5.0 -+ Added new parameter, `-IncludeDeserialized`, on `Add-PSTypeExtension` ([Issue #14](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/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`. +- Added new parameter, `-IncludeDeserialized`, on `Add-PSTypeExtension` ([Issue #14](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/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. -+ Modified manifest to support both Desktop and Core PSEditions. -+ Updates to some of the sample files. -+ Updated `README.md`. +- Modified manifest to require PowerShell 5.1. +- Modified manifest to support both Desktop and Core PSEditions. +- Updates to some of the sample files. +- Updated `README.md`. ## v1.3.0 -+ File cleanup for the PowerShell Gallery. -+ Exported Samples folder as a variable to make it easier to import. -+ code cleanup -+ markdown cleanup -+ help cleanup -+ Updates to `README.md` +- File cleanup for the PowerShell Gallery. +- Exported Samples folder as a variable to make it easier to import. +- code cleanup +- markdown cleanup +- help cleanup +- Updates to `README.md` ## v1.1.0 -+ Fixed `Import-PSTypeExtension` bug piping in json/xml files ([Issue #13](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/13)) -+ Updated About help documentation -+ Modified pipeline processing in `Get-PSTypeExtension` ([Issue #12](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/12)) +- Fixed `Import-PSTypeExtension` bug piping in json/xml files ([Issue #13](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/13)) +- Updated About help documentation +- Modified pipeline processing in `Get-PSTypeExtension` ([Issue #12](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/12)) ## v1.0.0 -+ Modified `Export-PSTypeExtension` to export to a ps1xml file ([Issue #11](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/11)) -+ release to the PowerShell Gallery -+ Updated documentation -+ Updated samples +- Modified `Export-PSTypeExtension` to export to a ps1xml file ([Issue #11](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/11)) +- release to the PowerShell Gallery +- Updated documentation +- Updated samples ## v0.5.1 -+ fixed bug in the CimInstance json sample -+ fixed link bug in README.md file +- fixed bug in the CimInstance json sample +- fixed link bug in README.md file ## v0.5.0 -+ Modified `Get-PSType` to better reflect type names. ([Issue #7](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/7)) -+ added additional sample files. -+ modified `Get-PSTypeExtension` to include PSTypeExtension as a typename -+ added format ps1xml (Issue #8) -+ revised parameter validation for `Get-PSTypeExtension` ([Issue #10](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/10)) -+ revised `Import-PSTypeExtension` to accept pipelined input for filenames ([Issue #9](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/9)) -+ updated documentation +- Modified `Get-PSType` to better reflect type names. ([Issue #7](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/7)) +- added additional sample files. +- modified `Get-PSTypeExtension` to include PSTypeExtension as a typename +- added format ps1xml (Issue #8) +- revised parameter validation for `Get-PSTypeExtension` ([Issue #10](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/10)) +- revised `Import-PSTypeExtension` to accept pipelined input for filenames ([Issue #9](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/9)) +- updated documentation ## v0.4.0 -+ Modified `Get-PSTypeExtension` so +All is the default ([Issue #6](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/6)) -+ Modified `Get-PSTypeExtension` to validate typename -+ Updated help documentation to include an About file -+ Reverted Changelog to a text file -+ Updated Strings sample file. +- Modified `Get-PSTypeExtension` so -All is the default ([Issue #6](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/6)) +- Modified `Get-PSTypeExtension` to validate typename +- Updated help documentation to include an About file +- Reverted Changelog to a text file +- Updated Strings sample file. ## v0.3.0 -+ fixed bug in `Get-PSTypeExtension` that was writing a blank object to the pipeline. ([Issue #3](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/3)) -+ Added support for WhatIf to `Export-PSTypeExtension` ([Issue #2](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/2)) -+ documentation update +- fixed bug in `Get-PSTypeExtension` that was writing a blank object to the pipeline. ([Issue #3](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/3)) +- Added support for WhatIf to `Export-PSTypeExtension` ([Issue #2](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/2)) +- documentation update ## v0.2.0 -+ renamed commands to be consistent with the module name -+ updated help documentation -+ Added `Set-PSTypeExtension` as an alias to `Add-PSTypeExtension` +- renamed commands to be consistent with the module name +- updated help documentation +- Added `Set-PSTypeExtension` as an alias to `Add-PSTypeExtension` ## v0.1.0 -+ major changes to functions and design -+ Added `Get-PSType` function -+ Added `Get-MyTypeExtension` function -+ Added `Get-MyTypeExtension` function +- major changes to functions and design +- Added `Get-PSType` function +- Added `Get-MyTypeExtension` function +- Added `Get-MyTypeExtension` function ## v0.0.4 -+ Updated to handle other member type ([Issue #2](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/2)) +- Updated to handle other member type ([Issue #2](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/2)) ## v0.0.3 -+ added ShouldSupportProcess for `Import-MyTypeExtension` ([Issue #1](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/1) -+ updated help -+ updated manifest +- added ShouldSupportProcess for `Import-MyTypeExtension` ([Issue #1](https://github.com/jdhitsolutions/PSTypeExtensionTools/issues/1) +- updated help +- updated manifest ## v0.0.2 -+ added a manifest +- added a manifest ## v0.0.1 -+ Initial module +- Initial module diff --git a/License.txt b/License.txt index 2dff7a8..ca7e8dc 100644 --- a/License.txt +++ b/License.txt @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2017-2022 JDH Information Technology Solutions, Inc. +Copyright (c) 2017-2024 JDH Information Technology Solutions, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy diff --git a/PSTypeExtensionTools.psd1 b/PSTypeExtensionTools.psd1 index bd67e64..b6ef92f 100644 Binary files a/PSTypeExtensionTools.psd1 and b/PSTypeExtensionTools.psd1 differ diff --git a/PSTypeExtensionTools.psm1 b/PSTypeExtensionTools.psm1 index 96e5b43..e2866d3 100644 --- a/PSTypeExtensionTools.psm1 +++ b/PSTypeExtensionTools.psm1 @@ -1,6 +1,5 @@ - Get-ChildItem $PSScriptRoot\Functions\*.ps1 | -Foreach-object { . $_.fullname} +Foreach-object { . $_.FullName} #Export the Samples folder location as a variable $PSTypeSamples = Join-Path $PSScriptRoot -ChildPath samples diff --git a/README.md b/README.md index cd02417..60e8fd2 100644 --- a/README.md +++ b/README.md @@ -68,7 +68,7 @@ Show-Command Add-PSTypeExtension Clicking Run will insert this code at your prompt. ```powershell -Add-PSTypeExtension -MemberName ToTitleCase -MemberType ScriptMethod -TypeName System.String -Value { (Get-Culture).TextInfo.ToTitleCase($this.tolower())} +Add-PSTypeExtension -MemberName ToTitleCase -MemberType ScriptMethod -TypeName System.String -Value { (Get-Culture).TextInfo.ToTitleCase($this.ToLower())} ``` If you like this extension, you can export it and re-import it later. @@ -134,7 +134,7 @@ Let's say you have loaded the sample 'System.IO.FileInfo` type extensions from t ```powershell Import-PSTypeExtension -Path $PSTypeSamples\fileinfo-extensions.json -```powershell +``` You could write a command like this: @@ -145,25 +145,25 @@ 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 +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. ```dos -PS C:\> Update-TypeData $PSTypeSamples\fileinfo.types.ps1xml -PS C:\> dir c:\work -file | Select-Object fileage +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 +a.dat 42 2/12/2024 5:36:55 PM 23.17:27:21 +a.txt 14346 12/31/2023 9:10:15 AM 67.01:54:00 +a.xml 171394 12/31/2023 12:15:44 PM 66.22:48:32 +aa.ps1 28866 12/31/2023 9:13:16 AM 67.01:51:00 +aa.txt 28866 12/31/2023 9:11:18 AM 67.01:52:58 +about.json 16455 2/27/2024 10:11:03 AM 09.00:53:12 +about_ADReportingTools 1688 3/4/2024 7:37:01 PM 03.15:27:14 +b.csv 1273 11/13/2023 12:11:35 PM 114.22:52:40 ... ``` @@ -180,20 +180,20 @@ Here's how this might look. First, create a property set file. ```powershell -New-PSPropertySet -Typename system.io.fileinfo -Name TimeSet -Properties "Name","Length","CreationTime","LastWriteTime" -FilePath c:\work\file.types.ps1xml +New-PSPropertySet -Typename System.IO.FileInfo -Name TimeSet -Properties "Name","Length","CreationTime","LastWriteTime" -FilePath c:\work\file.types.ps1xml ``` I'll define a few type extensions. ```powershell -Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType AliasProperty -MemberName Size -Value Length -Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType ScriptProperty -MemberName ModifiedAge -Value {New-TimeSpan -Start $this.lastwritetime -End (Get-Date)} +Add-PSTypeExtension -TypeName System.IO.FileInfo -MemberType AliasProperty -MemberName Size -Value Length +Add-PSTypeExtension -TypeName System.IO.FileInfo -MemberType ScriptProperty -MemberName ModifiedAge -Value {New-TimeSpan -Start $this.LastWriteTime -End (Get-Date)} ``` I'll even add a second property set to the same file using these new extensions. ```powershell -Export-PSTypeExtension -TypeName system.io.fileinfo -MemberName Size,ModifiedAge -Path c:\work\file.types.ps1xml -append +Export-PSTypeExtension -TypeName System.IO.FileInfo -MemberName Size,ModifiedAge -Path c:\work\file.types.ps1xml -append ``` I'll end up with this file: @@ -207,7 +207,7 @@ the PowerShell Gallery. Use Update-TypeData to append this file in your PowerShell session. -Created 03/09/2021 15:27:56 +Created 03/09/2024 15:27:56 --> @@ -247,21 +247,22 @@ Created 03/09/2021 15:27:56 In PowerShell, I can load this file and use it. ```powershell -PS C:\> Update-Typedata c:\work\file.types.ps1xml -PS C:\> Get-Childitem -path c:\work\*.csv | Sort-Object -property size -Descending | Select Age +PS C:\> Update-TypeData c:\work\file.types.ps1xml +PS C:\> Get-ChildItem -path c:\work\*.csv | +Sort-Object -property size -Descending | Select Age Name Size LastWriteTime ModifiedAge ---- ---- ------------- ----------- -updates.csv 4021821 11/14/2020 9:00:48 AM 115.06:45:35.2595780 -part5.csv 7332 2/27/2021 6:10:11 PM 9.21:36:12.4672428 -ipperf.csv 5008 11/4/2020 11:36:20 AM 125.04:10:03.4641251 -localusers.csv 1480 2/27/2021 4:39:32 PM 9.23:06:51.7431393 -b.csv 1273 11/13/2020 12:11:35 PM 116.03:34:48.0298279 -foo.csv 1077 11/13/2020 12:40:04 PM 116.03:06:19.3069112 -y.csv 524 11/19/2020 2:11:44 PM 110.01:34:39.0826388 -yy.csv 524 12/1/2020 11:28:03 AM 98.04:18:20.7080948 -c.csv 334 11/13/2020 11:58:15 AM 116.03:48:08.3898463 -a.csv 0 12/1/2020 11:30:55 AM 98.04:15:27.9106911 +updates.csv 4021821 11/14/2023 9:00:48 AM 115.06:45:35.2595780 +part5.csv 7332 2/27/2024 6:10:11 PM 9.21:36:12.4672428 +ipperf.csv 5008 11/4/2023 11:36:20 AM 125.04:10:03.4641251 +localusers.csv 1480 2/27/2024 4:39:32 PM 9.23:06:51.7431393 +b.csv 1273 11/13/2023 12:11:35 PM 116.03:34:48.0298279 +foo.csv 1077 11/13/2023 12:40:04 PM 116.03:06:19.3069112 +y.csv 524 11/19/2023 2:11:44 PM 110.01:34:39.0826388 +yy.csv 524 12/1/2023 11:28:03 AM 98.04:18:20.7080948 +c.csv 334 11/13/2023 11:58:15 AM 116.03:48:08.3898463 +a.csv 0 12/1/2023 11:30:55 AM 98.04:15:27.9106911 ``` I can put the `Update-TypeData` command in my PowerShell profile to always have these extensions. Or I could share the file. @@ -279,16 +280,16 @@ PS C:\> Get-ChildItem $PSTypeSamples Mode LastWriteTime Length Name ---- ------------- ------ ---- --a---- 12/15/2017 2:25 PM 766 cimlogicaldisk-extensions.json --a---- 9/28/2018 9:48 AM 265 datetime-extensions.json --a---- 12/15/2017 5:09 PM 232 eventlog-type.json --a---- 2/18/2019 1:18 PM 1266 fileinfo-extensions.json --a---- 11/13/2017 8:37 AM 901 int32-types.json --a---- 11/1/2017 6:18 PM 653 measure-extensions.json --a---- 11/13/2017 8:49 AM 890 process-types.xml --a---- 12/15/2017 6:09 PM 628 README.md --a---- 12/15/2017 2:09 PM 1246 stringtypes.json --a---- 11/9/2017 12:08 PM 3024 vm-extensions.json +-a---- 12/15/2023 2:25 PM 766 cimlogicaldisk-extensions.json +-a---- 9/28/2024 9:48 AM 265 datetime-extensions.json +-a---- 12/15/2023 5:09 PM 232 eventlog-type.json +-a---- 2/18/2024 1:18 PM 1266 fileinfo-extensions.json +-a---- 11/13/2023 8:37 AM 901 int32-types.json +-a---- 11/1/2023 6:18 PM 653 measure-extensions.json +-a---- 11/13/2023 8:49 AM 890 process-types.xml +-a---- 12/15/2023 6:09 PM 628 README.md +-a---- 12/15/2023 2:09 PM 1246 stringtypes.json +-a---- 11/9/2023 12:08 PM 3024 vm-extensions.json PS C:\> Import-PSTypeExtension $PSTypeSamples\measure-extensions.json -Verbose VERBOSE: Starting: Import-PSTypeExtension diff --git a/docs/Add-PSTypeExtension.md b/docs/Add-PSTypeExtension.md index 9a811f8..a8429bd 100644 --- a/docs/Add-PSTypeExtension.md +++ b/docs/Add-PSTypeExtension.md @@ -45,7 +45,7 @@ Define a script property called IsIPAddress which will return True if the string ### EXAMPLE 3 ```powershell -PS C:\ Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType AliasProperty -MemberName Size -value Length -IncludeDeserialized +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 it for the deserialized version of the type so that you can use it with remoting results. diff --git a/docs/Export-PSTypeExtension.md b/docs/Export-PSTypeExtension.md index f0979fe..a8a0a4a 100644 --- a/docs/Export-PSTypeExtension.md +++ b/docs/Export-PSTypeExtension.md @@ -70,7 +70,7 @@ Export the selected members to a ps1xml file and pass the file object to the pip ```powershell PS C:\work> Get-PSTypeExtension system.string | Export-PSTypeExtension -Path .\all.ps1xml -PS C:\work> Get-PSTypeExtension system.io.fileinfo | +PS C:\work> Get-PSTypeExtension System.IO.FileInfo | Export-PSTypeExtension -Path .\all.ps1xml -append PS C:\work> Get-PSTypeExtension system.serviceprocess.servicecontroller -Members State | Export-PSTypeExtension -Path .\all.ps1xml -append ``` diff --git a/docs/Get-PSType.md b/docs/Get-PSType.md index 46bec4a..7ee477a 100644 --- a/docs/Get-PSType.md +++ b/docs/Get-PSType.md @@ -14,7 +14,7 @@ Get the type name for a given object. ## SYNTAX ```yaml -Get-PSType [-Inputobject] [] +Get-PSType [-InputObject] [] ``` ## DESCRIPTION @@ -50,26 +50,26 @@ Pipe an object to get its type and then pipe that name to Get-PSTypeExtension to ### EXAMPLE 3 ```powershell -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 +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 Name CreationTime VMAge ---- ------------ ----- -UbuntuDesk 8/7/2020 1:53:47 PM 94.20:26:57.4237225 -CentOS 8/7/2020 3:43:50 PM 94.18:36:54.3394091 -DOM1 9/28/2020 9:31:34 AM 43.00:49:10.4396803 -SRV1 9/28/2020 9:31:50 AM 43.00:48:54.3284313 -SRV2 9/28/2020 9:32:01 AM 43.00:48:43.2135084 -SRV3 9/28/2020 9:32:11 AM 43.00:48:33.4681374 -WIN10 9/28/2020 9:32:21 AM 43.00:48:23.1610914 -Win10Ent 10/16/2020 9:30:46 AM 25.00:49:58.1206825 +UbuntuDesk 8/7/2023 1:53:47 PM 94.20:26:57.4237225 +CentOS 8/7/2023 3:43:50 PM 94.18:36:54.3394091 +DOM1 9/28/2023 9:31:34 AM 43.00:49:10.4396803 +SRV1 9/28/2023 9:31:50 AM 43.00:48:54.3284313 +SRV2 9/28/2023 9:32:01 AM 43.00:48:43.2135084 +SRV3 9/28/2023 9:32:11 AM 43.00:48:33.4681374 +WIN10 9/28/2023 9:32:21 AM 43.00:48:23.1610914 +Win10Ent 10/16/2023 9:30:46 AM 25.00:49:58.1206825 ``` Get the type for a Hyper-V Virtual Machine and add a new ScriptProperty, which can then be used in a PowerShell expression. ## PARAMETERS -### -Inputobject +### -InputObject Any object from PowerShell. diff --git a/docs/Get-PSTypeExtension.md b/docs/Get-PSTypeExtension.md index 761c6c5..f876664 100644 --- a/docs/Get-PSTypeExtension.md +++ b/docs/Get-PSTypeExtension.md @@ -14,7 +14,7 @@ Get selected type extensions. ## SYNTAX ```yaml -Get-PSTypeExtension [-TypeName] [-Members ] [-CodeProperty] [] +Get-PSTypeExtension [-TypeName] [-Members ] [-CodeProperty] [] ``` ## DESCRIPTION @@ -74,13 +74,13 @@ VM AliasProperty VirtualMemorySize64 WS AliasProperty WorkingSet64 PM AliasProperty PagedMemorySize64 NPM AliasProperty NonpagedSystemMemorySize64 -Path ScriptProperty $this.Mainmodule.FileName -Company ScriptProperty $this.Mainmodule.FileVersionInfo.CompanyName +Path ScriptProperty $this.MainModule.FileName +Company ScriptProperty $this.MainModule.FileVersionInfo.CompanyName CPU ScriptProperty $this.TotalProcessorTime.TotalSeconds -FileVersion ScriptProperty $this.Mainmodule.FileVersionInfo.FileVersion -ProductVersion ScriptProperty $this.Mainmodule.FileVersionInfo.ProductVersion -Description ScriptProperty $this.Mainmodule.FileVersionInfo.FileDescription -Product ScriptProperty $this.Mainmodule.FileVersionInfo.ProductName +FileVersion ScriptProperty $this.MainModule.FileVersionInfo.FileVersion +ProductVersion ScriptProperty $this.MainModule.FileVersionInfo.ProductVersion +Description ScriptProperty $this.MainModule.FileVersionInfo.FileDescription +Product ScriptProperty $this.MainModule.FileVersionInfo.ProductName __NounName Noteproperty Process ``` @@ -89,8 +89,8 @@ Discover type extensions for a given type of object. ### Example 4 ```powershell -PS C:\> Get-PSTypeExtension system.io.fileinfo -CodeProperty | -Select-Object membername,membertype +PS C:\> Get-PSTypeExtension System.IO.FileInfo -CodeProperty | +Select-Object MemberName,MemberType MemberName MemberType ---------- ---------- diff --git a/docs/Import-PSTypeExtension.md b/docs/Import-PSTypeExtension.md index 9ef8d0c..7a7f919 100644 --- a/docs/Import-PSTypeExtension.md +++ b/docs/Import-PSTypeExtension.md @@ -48,7 +48,7 @@ The name of the imported file. The extension must be .xml or .json. ```yaml Type: String Parameter Sets: (All) -Aliases: fullname +Aliases: FullName Required: True Position: 0 diff --git a/docs/New-PSPropertySet.md b/docs/New-PSPropertySet.md index c046433..5393a81 100644 --- a/docs/New-PSPropertySet.md +++ b/docs/New-PSPropertySet.md @@ -44,13 +44,13 @@ PS C:\> dir c:\work -file | select info FullName IsReadOnly CreationTime LastWriteTime -------- ---------- ------------ ------------- -C:\work\a.csv False 12/1/2020 11:30:55 AM 12/1/2020 11:30:55 AM -C:\work\a.dat False 2/12/2021 5:36:55 PM 2/12/2021 5:36:55 PM -C:\work\a.md False 11/6/2020 9:50:19 AM 12/1/2020 12:40:03 PM -C:\work\a.txt False 12/31/2020 9:10:15 AM 12/31/2020 9:10:15 AM -C:\work\a.xml False 12/31/2020 12:15:44 PM 12/31/2020 12:15:44 PM -C:\work\aa.ps1 False 12/31/2020 9:13:16 AM 12/31/2020 9:13:16 AM -C:\work\aa.txt False 12/31/2020 9:11:18 AM 12/31/2020 9:11:18 AM +C:\work\a.csv False 12/1/2023 11:30:55 AM 12/1/2023 11:30:55 AM +C:\work\a.dat False 2/12/2024 5:36:55 PM 2/12/2024 5:36:55 PM +C:\work\a.md False 11/6/2023 9:50:19 AM 12/1/2023 12:40:03 PM +C:\work\a.txt False 12/31/2023 9:10:15 AM 12/31/2023 9:10:15 AM +C:\work\a.xml False 12/31/2023 12:15:44 PM 12/31/2023 12:15:44 PM +C:\work\aa.ps1 False 12/31/2023 9:13:16 AM 12/31/2023 9:13:16 AM +C:\work\aa.txt False 12/31/2023 9:11:18 AM 12/31/2023 9:11:18 AM ... ``` diff --git a/docs/about_PSTypeExtensionTools.md b/docs/about_PSTypeExtensionTools.md index fed777d..2ce31d8 100644 --- a/docs/about_PSTypeExtensionTools.md +++ b/docs/about_PSTypeExtensionTools.md @@ -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 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. +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](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 @@ -100,7 +100,7 @@ Import-PSTypeExtension $PSTypeSamples\measure-extensions.json The `Export-PSTypeExtension` command will also export extensions to a properly formatted .ps1xml file. This can be useful when building type extension files for a module where you want to use the traditional ps1xml form. You can also import these types of files with `Update-TypeData` with the -AppendPath or -PrependPath parameters. -When exporting to .ps1xml file, `Export-PSTypeExtension` has a dynamic parameter, `Append`. Tis allows you to combine multiple type extensions into a single file. If you intend to use a property set, create that file first. Then append your custom type extensions to that file. +When exporting to .ps1xml file, `Export-PSTypeExtension` has a dynamic parameter, `Append`. This allows you to combine multiple type extensions into a single file. If you intend to use a property set, create that file first. Then append your custom type extensions to that file. ## NOTE @@ -116,20 +116,18 @@ Remember to enclose scriptblocks in {}. ## SEE ALSO -+ [Add-PSTypeExtension](Add-PSTypeExtension.md) -+ [Export-PSTypeExtension](Export-PSTypeExtension.md) -+ [Get-PSType](Get-PSType.md) -+ [Get-PSTypeExtension](Get-PSTypeExtension.md) -+ [Import-PSTypeExtension](Import-PSTypeExtension.md) -+ [Update-TypeData](Update-TypeData.md) -+ [New-PSPropertySet](New-PSPropertySet.md) +- [Add-PSTypeExtension](Add-PSTypeExtension.md) +- [Export-PSTypeExtension](Export-PSTypeExtension.md) +- [Get-PSType](Get-PSType.md) +- [Get-PSTypeExtension](Get-PSTypeExtension.md) +- [Import-PSTypeExtension](Import-PSTypeExtension.md) +- [Update-TypeData](Update-TypeData.md) +- [New-PSPropertySet](New-PSPropertySet.md) This project was first described at http://jdhitsolutions.com/blog/powershell/5777/a-powershell-module-for-your-type-extensions ## KEYWORDS -- typedata - -- typeextension - -- propertyset +- TypeData +- TypeExtension +- PropertySet diff --git a/en-us/PSTypeExtensionTools-help.xml b/en-us/PSTypeExtensionTools-help.xml index efd3c7a..48b37f3 100644 --- a/en-us/PSTypeExtensionTools-help.xml +++ b/en-us/PSTypeExtensionTools-help.xml @@ -235,7 +235,7 @@ True -------------------------- EXAMPLE 3 -------------------------- - PS C:\ Add-PSTypeExtension -TypeName system.io.fileinfo -MemberType AliasProperty -MemberName Size -value Length -IncludeDeserialized + 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 it for the deserialized version of the type so that you can use it with remoting results. @@ -558,7 +558,7 @@ Mode LastWriteTime Length Name -------------------------- EXAMPLE 4 -------------------------- PS C:\work> Get-PSTypeExtension system.string | Export-PSTypeExtension -Path .\all.ps1xml -PS C:\work> Get-PSTypeExtension system.io.fileinfo | +PS C:\work> Get-PSTypeExtension System.IO.FileInfo | Export-PSTypeExtension -Path .\all.ps1xml -append PS C:\work> Get-PSTypeExtension system.serviceprocess.servicecontroller -Members State | Export-PSTypeExtension -Path .\all.ps1xml -append @@ -597,7 +597,7 @@ PS C:\work> Get-PSTypeExtension system.serviceprocess.servicecontroller -Mem Get-PSType - Inputobject + InputObject Any object from PowerShell. @@ -612,7 +612,7 @@ PS C:\work> Get-PSTypeExtension system.serviceprocess.servicecontroller -Mem - Inputobject + InputObject Any object from PowerShell. @@ -674,19 +674,19 @@ IsIPAddress ScriptMethod $this -match "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,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 + 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 Name CreationTime VMAge ---- ------------ ----- -UbuntuDesk 8/7/2020 1:53:47 PM 94.20:26:57.4237225 -CentOS 8/7/2020 3:43:50 PM 94.18:36:54.3394091 -DOM1 9/28/2020 9:31:34 AM 43.00:49:10.4396803 -SRV1 9/28/2020 9:31:50 AM 43.00:48:54.3284313 -SRV2 9/28/2020 9:32:01 AM 43.00:48:43.2135084 -SRV3 9/28/2020 9:32:11 AM 43.00:48:33.4681374 -WIN10 9/28/2020 9:32:21 AM 43.00:48:23.1610914 -Win10Ent 10/16/2020 9:30:46 AM 25.00:49:58.1206825 +UbuntuDesk 8/7/2023 1:53:47 PM 94.20:26:57.4237225 +CentOS 8/7/2023 3:43:50 PM 94.18:36:54.3394091 +DOM1 9/28/2023 9:31:34 AM 43.00:49:10.4396803 +SRV1 9/28/2023 9:31:50 AM 43.00:48:54.3284313 +SRV2 9/28/2023 9:32:01 AM 43.00:48:43.2135084 +SRV3 9/28/2023 9:32:11 AM 43.00:48:33.4681374 +WIN10 9/28/2023 9:32:21 AM 43.00:48:23.1610914 +Win10Ent 10/16/2023 9:30:46 AM 25.00:49:58.1206825 Get the type for a Hyper-V Virtual Machine and add a new ScriptProperty, which can then be used in a PowerShell expression. @@ -874,13 +874,13 @@ VM AliasProperty VirtualMemorySize64 WS AliasProperty WorkingSet64 PM AliasProperty PagedMemorySize64 NPM AliasProperty NonpagedSystemMemorySize64 -Path ScriptProperty $this.Mainmodule.FileName -Company ScriptProperty $this.Mainmodule.FileVersionInfo.CompanyName +Path ScriptProperty $this.MainModule.FileName +Company ScriptProperty $this.MainModule.FileVersionInfo.CompanyName CPU ScriptProperty $this.TotalProcessorTime.TotalSeconds -FileVersion ScriptProperty $this.Mainmodule.FileVersionInfo.FileVersion -ProductVersion ScriptProperty $this.Mainmodule.FileVersionInfo.ProductVersion -Description ScriptProperty $this.Mainmodule.FileVersionInfo.FileDescription -Product ScriptProperty $this.Mainmodule.FileVersionInfo.ProductName +FileVersion ScriptProperty $this.MainModule.FileVersionInfo.FileVersion +ProductVersion ScriptProperty $this.MainModule.FileVersionInfo.ProductVersion +Description ScriptProperty $this.MainModule.FileVersionInfo.FileDescription +Product ScriptProperty $this.MainModule.FileVersionInfo.ProductName __NounName Noteproperty Process Discover type extensions for a given type of object. @@ -888,8 +888,8 @@ __NounName Noteproperty Process -------------------------- Example 4 -------------------------- - PS C:\> Get-PSTypeExtension system.io.fileinfo -CodeProperty | -Select-Object membername,membertype + PS C:\> Get-PSTypeExtension System.IO.FileInfo -CodeProperty | +Select-Object MemberName,MemberType MemberName MemberType ---------- ---------- @@ -946,7 +946,7 @@ SizeMB ScriptProperty Import-PSTypeExtension - + Path The name of the imported file. The extension must be .xml or .json. @@ -983,7 +983,7 @@ SizeMB ScriptProperty - + Path The name of the imported file. The extension must be .xml or .json. @@ -1396,13 +1396,13 @@ PS C:\> dir c:\work -file | select info FullName IsReadOnly CreationTime LastWriteTime -------- ---------- ------------ ------------- -C:\work\a.csv False 12/1/2020 11:30:55 AM 12/1/2020 11:30:55 AM -C:\work\a.dat False 2/12/2021 5:36:55 PM 2/12/2021 5:36:55 PM -C:\work\a.md False 11/6/2020 9:50:19 AM 12/1/2020 12:40:03 PM -C:\work\a.txt False 12/31/2020 9:10:15 AM 12/31/2020 9:10:15 AM -C:\work\a.xml False 12/31/2020 12:15:44 PM 12/31/2020 12:15:44 PM -C:\work\aa.ps1 False 12/31/2020 9:13:16 AM 12/31/2020 9:13:16 AM -C:\work\aa.txt False 12/31/2020 9:11:18 AM 12/31/2020 9:11:18 AM +C:\work\a.csv False 12/1/2023 11:30:55 AM 12/1/2023 11:30:55 AM +C:\work\a.dat False 2/12/2024 5:36:55 PM 2/12/2024 5:36:55 PM +C:\work\a.md False 11/6/2023 9:50:19 AM 12/1/2023 12:40:03 PM +C:\work\a.txt False 12/31/2023 9:10:15 AM 12/31/2023 9:10:15 AM +C:\work\a.xml False 12/31/2023 12:15:44 PM 12/31/2023 12:15:44 PM +C:\work\aa.ps1 False 12/31/2023 9:13:16 AM 12/31/2023 9:13:16 AM +C:\work\aa.txt False 12/31/2023 9:11:18 AM 12/31/2023 9:11:18 AM ... The first command creates the property set definition file. The second command loads it into PowerShell. The last command uses the custom property set. diff --git a/en-us/about_PSTypeExtensionTools.help.txt b/en-us/about_PSTypeExtensionTools.help.txt index 1ba028d..ff0f640 100644 --- a/en-us/about_PSTypeExtensionTools.help.txt +++ b/en-us/about_PSTypeExtensionTools.help.txt @@ -3,8 +3,8 @@ 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 + e extensny of thesemands are wrappers for built-in tools like + Get-TypeData or Update-TypeData. The commands in this module simplify the process of finding, creating, exporting, and importing type extensions. LONG DESCRIPTION @@ -13,10 +13,10 @@ LONG DESCRIPTION could run a PowerShell command like this: PS C:\> 123 | Get-PSType | - Add-PSTypeExtension -MemberType ScriptProperty -MemberName SquareRoot ` + Add-PSTypeExtension -MemberType ScriptProperty -MemberName SquareRoot -Value { [math]::Sqrt($this)} - Use `$this` to reference the object instead of $_. Now you can get the new + Use $this to reference the object instead of $_. Now you can get the new property. PS C:\> $x = 123 @@ -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) @@ -46,13 +46,13 @@ LONG DESCRIPTION PS C:\> $x.GetPercent(110,4) 34.5455 - To see what has been defined, you can use `Get-PSTypeExtension`. You can + 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 - + TypeName: System.Int32 - + Name Type Value ---- ---- ----- SquareRoot ScriptProperty [math]::Sqrt($this) @@ -80,54 +80,49 @@ LONG DESCRIPTION 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. + https://github.com/jdhitsolutions/PSTypeExtensionTools/tree/master/samples. + When have imported the module, you can access the samples folder using + the $PSTypeSamples variable. Import-PSTypeExtension $PSTypeSamples\measure-extensions.json - CREATING PS1XML FILES - The `Export-PSTypeExtension` command will also export extensions to a + The Export-PSTypeExtension command will also export extensions to a properly formatted .ps1xml file. This can be useful when building type - extension files for a module where you want to use the traditional ps1xml - form. You can also import these types of files with `Update-TypeData` with + extension files for a module where you want to use traditional ps1xml + form. You can also import these types of files with Update-TypeData with the -AppendPath or -PrependPath parameters. - When exporting to .ps1xml file, `Export-PSTypeExtension` has a dynamic - parameter, `Append`. Tis allows you to combine multiple type extensions into + + When exporting the ps1xml file, Export-PSTypeExtension has a dynamic parameter + called Append. This allows you to combine multiple type extensions into a single file. If you intend to use a property set, create that file first. Then append your custom type extensions to that file. NOTE PowerShell type extensions only last for the duration of your PowerShell - session. If you make a mistake that is causing problems, restart PowerShell - or use the `Remove-TypeData` cmdlet. + session. Iu make a mistake that is causing problems, restart PowerShell + or use the Remove-TypeData cmdlet. TROUBLESHOOTING NOTE Don't try to append or manually update an export file. If you have changes, - re-run the export command and generate the file anew. - Remember to use `$this` to reference the object and NOT `$_`. + re-run the export and generate the file anew. Remember to use $this to + reference the object and NOT $_. + Remember to enclose scriptblocks in {}. SEE ALSO - + Add-PSTypeExtension - + Export-PSTypeExtension - + Get-PSType - + Get-PSTypeExtension - + Import-PSTypeExtension - + Update-TypeData - + New-PSPropertySet + This project was first described at http://jdhitsolutions.com/blog/powershell/5777/a-powershell-module-for-your-type-extensions KEYWORDS - - typedata -- typeextension -- propertyset + - TypeData + - TypeExtension + - PropertySet diff --git a/formats/PSTypeExtension.format.ps1xml b/formats/PSTypeExtension.format.ps1xml index 64a65c4..b945ac9 100644 --- a/formats/PSTypeExtension.format.ps1xml +++ b/formats/PSTypeExtension.format.ps1xml @@ -7,7 +7,7 @@ PSTypeExtension - TypeName + TypeName diff --git a/functions/Add-PSTypeExtension.ps1 b/functions/Add-PSTypeExtension.ps1 index ce9bfb7..72f3669 100644 --- a/functions/Add-PSTypeExtension.ps1 +++ b/functions/Add-PSTypeExtension.ps1 @@ -1,5 +1,5 @@ Function Add-PSTypeExtension { - [cmdletbinding(SupportsShouldProcess)] + [CmdletBinding(SupportsShouldProcess)] [Alias('Set-PSTypeExtension')] Param( @@ -7,22 +7,22 @@ Function Add-PSTypeExtension { Position = 0, Mandatory, ValueFromPipeline, - HelpMessage = "Enter the name of a type like system.io.fileinfo")] - [string]$TypeName, + HelpMessage = "Enter the name of a type like System.IO.FileInfo")] + [String]$TypeName, [Parameter( Mandatory, HelpMessage = "The member type" )] - [ValidateSet("AliasProperty", "Noteproperty", "ScriptProperty", "ScriptMethod")] + [ValidateSet("AliasProperty", "NoteProperty", "ScriptProperty", "ScriptMethod")] [alias("Type")] - [string]$MemberType, + [String]$MemberType, [Parameter( Mandatory, HelpMessage = "The name of your type extension" )] [ValidateNotNullOrEmpty()] [alias("Name")] - [string]$MemberName, + [String]$MemberName, [Parameter( Mandatory, HelpMessage = "The value for your type extension. Remember to enclose scriptblocks in {} and use `$this" @@ -30,10 +30,10 @@ Function Add-PSTypeExtension { [ValidateNotNullOrEmpty()] [Object]$Value, [Parameter(HelpMessage = "Create the extension in the deserialized version of the specified type including the original type.")] - [switch]$IncludeDeserialized + [Switch]$IncludeDeserialized ) Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" } #begin @@ -42,18 +42,18 @@ Function Add-PSTypeExtension { $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)" + $PSBoundParameters.TypeName = "deserialized.$TypeName" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding $MemberType $MemberName to $($PSBoundParameters.TypeName)" Update-TypeData @PSBoundParameters - $PSBoundParameters.Typename = $Typename + $PSBoundParameters.TypeName = $TypeName } - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding $MemberType $Membername to $($psboundparameters.TypeName)" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding $MemberType $MemberName to $($PSBoundParameters.TypeName)" Update-TypeData @PSBoundParameters } #process End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #end -} #close Add-MyTypeExtension \ No newline at end of file +} #close Add-MyTypeExtension diff --git a/functions/Export-PSTypeExtension.ps1 b/functions/Export-PSTypeExtension.ps1 index ab40205..cb92286 100644 --- a/functions/Export-PSTypeExtension.ps1 +++ b/functions/Export-PSTypeExtension.ps1 @@ -1,5 +1,5 @@ Function Export-PSTypeExtension { - [cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "Object")] + [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "Object")] Param( [Parameter( Position = 0, @@ -8,7 +8,7 @@ Function Export-PSTypeExtension { ParameterSetName = "Name" )] [ValidateNotNullOrEmpty()] - [string]$TypeName, + [String]$TypeName, [Parameter( Mandatory, @@ -23,12 +23,12 @@ Function Export-PSTypeExtension { HelpMessage = "The name of the export file. The extension must be .json,.xml or .ps1xml" )] [ValidatePattern("\.(xml|json|ps1xml)$")] - [string]$Path, + [String]$Path, [Parameter(ParameterSetName = "Object", ValueFromPipeline)] [object]$InputObject, - [switch]$Passthru + [Switch]$PassThru ) DynamicParam { #create a dynamic parameter to append to .ps1xml files. @@ -55,8 +55,8 @@ Function Export-PSTypeExtension { } #dynamic parameter Begin { - Write-Verbose "Starting: $($MyInvocation.Mycommand)" - Write-Verbose "Detected parameter set $($pscmdlet.ParameterSetName)" + Write-Verbose "Starting: $($MyInvocation.MyCommand)" + Write-Verbose "Detected parameter set $($PSCmdlet.ParameterSetName)" $PathParent = Split-Path -Path $Path if (Test-Path -Path $PathParent) { @@ -80,26 +80,26 @@ Function Export-PSTypeExtension { $data = [System.Collections.Generic.list[object]]::new() if ($TypeName) { - Write-Verbose "Converting $typename to properly cased type name." + Write-Verbose "Converting $TypeName to properly cased type name." $TypeName = _convertTypeName $TypeName } } Process { #test if parent path exists If ($validPath) { - if ($Inputobject) { + if ($InputObject) { Write-Verbose "Processing input type: $($InputObject.TypeName)" - Write-Verbose "Converting $($InputObject.typename) to properly cased type name." + Write-Verbose "Converting $($InputObject.TypeName) to properly cased type name." $TypeName = _convertTypeName $InputObject.TypeName $data.Add($InputObject) } else { Write-Verbose "Processing type: $TypeName" - foreach ($member in $membername) { - $typemember = Get-PSTypeExtension -TypeName $Typename -Members $Member - $data.Add($typemember) + foreach ($member in $MemberName) { + $TypeMember = Get-PSTypeExtension -TypeName $TypeName -Members $Member + $data.Add($TypeMember) } } } #test path parent @@ -109,56 +109,55 @@ Function Export-PSTypeExtension { Write-Verbose "Exporting data to $path" if ($Path -match "\.ps1xml$") { - if ($PSBoundParameters["Append"]) { - $cpath = Convert-Path $path - Write-Verbose "Appending to $cpath" + $cPath = Convert-Path $path + Write-Verbose "Appending to $cPath" [xml]$doc = Get-Content $cPath - $members = $doc.types.SelectNodes("Type[Name='$typeName']").Members + $members = $doc.types.SelectNodes("Type[Name='$TypeName']").Members if ($members) { - Write-Verbose "Appending to existing typename entry" + Write-Verbose "Appending to existing TypeName entry" } else { - Write-Verbose "Creating a new typename entry for $TypeName" + Write-Verbose "Creating a new TypeName entry for $TypeName" $main = $doc.CreateNode("element", "Type", $null) $tName = $doc.CreateElement("Name") - $tName.InnerText = $typename - [void]($main.AppendChild($tname)) + $tName.InnerText = $TypeName + [void]($main.AppendChild($tName)) $members = $doc.CreateNode("element", "Members", $null) $IsNewType = $True } foreach ($extension in $data) { - Write-Verbose "Exporting $($extension.membername)" - $membertype = $doc.createNode("element", $extension.memberType, $null) - $membernameEL = $doc.CreateElement("Name") + Write-Verbose "Exporting $($extension.MemberName)" + $MemberType = $doc.createNode("element", $extension.MemberType, $null) + $MemberNameEL = $doc.CreateElement("Name") - $membernameEL.innertext = $extension.memberName - [void]($membertype.AppendChild($membernameEL)) + $MemberNameEL.InnerText = $extension.MemberName + [void]($MemberType.AppendChild($MemberNameEL)) - Switch ($extension.Membertype) { + Switch ($extension.MemberType) { "ScriptMethod" { - $memberdef = $doc.createelement("Script") + $MemberDef = $doc.CreateElement("Script") } "ScriptProperty" { - $memberdef = $doc.createelement("GetScriptBlock") + $MemberDef = $doc.CreateElement("GetScriptBlock") } "AliasProperty" { - $memberdef = $doc.createelement("ReferencedMemberName") + $MemberDef = $doc.CreateElement("ReferencedMemberName") } "NoteProperty" { - $memberdef = $doc.createelement("Value") + $MemberDef = $doc.CreateElement("Value") } Default { Throw "Can't process a type of $($extension.MemberType)" } - } #switch membertype + } #switch MemberType - $memberdef.InnerText = $extension.value - [void]($membertype.AppendChild($memberdef)) - [void]($members.AppendChild($membertype)) + $MemberDef.InnerText = $extension.value + [void]($MemberType.AppendChild($MemberDef)) + [void]($members.AppendChild($MemberType)) } #foreach extension @@ -168,9 +167,9 @@ Function Export-PSTypeExtension { [void]($doc.types.AppendChild($main)) } - if ($PSCmdlet.ShouldProcess($cpath)) { - $doc.save($cpath) - } #end Whatif + if ($PSCmdlet.ShouldProcess($cPath)) { + $doc.save($cPath) + } #end WhatIf } #if append @@ -203,37 +202,37 @@ Created $(Get-Date) $root = $doc.CreateNode("element", "Types", $null) $main = $doc.CreateNode("element", "Type", $null) $name = $doc.CreateElement("Name") - $name.innerText = $data[0].TypeName + $name.InnerText = $data[0].TypeName [void]($main.AppendChild($name)) $members = $doc.CreateNode("element", "Members", $null) foreach ($extension in $data) { - Write-Verbose "Exporting $($extension.membername)" - $membertype = $doc.createNode("element", $extension.memberType, $null) - $membernameEL = $doc.CreateElement("Name") + Write-Verbose "Exporting $($extension.MemberName)" + $MemberType = $doc.createNode("element", $extension.MemberType, $null) + $MemberNameEL = $doc.CreateElement("Name") - $membernameEL.innertext = $extension.memberName - [void]($membertype.AppendChild($membernameEL)) + $MemberNameEL.InnerText = $extension.MemberName + [void]($MemberType.AppendChild($MemberNameEL)) - Switch ($extension.Membertype) { + Switch ($extension.MemberType) { "ScriptMethod" { - $memberdef = $doc.createelement("Script") + $MemberDef = $doc.CreateElement("Script") } "ScriptProperty" { - $memberdef = $doc.createelement("GetScriptBlock") + $MemberDef = $doc.CreateElement("GetScriptBlock") } "AliasProperty" { - $memberdef = $doc.createelement("ReferencedMemberName") + $MemberDef = $doc.CreateElement("ReferencedMemberName") } "NoteProperty" { - $memberdef = $doc.createelement("Value") + $MemberDef = $doc.CreateElement("Value") } Default { Throw "Can't process a type of $($extension.MemberType)" } } - $memberdef.InnerText = $extension.value - [void]($membertype.AppendChild($memberdef)) - [void]($members.AppendChild($membertype)) + $MemberDef.InnerText = $extension.value + [void]($MemberType.AppendChild($MemberDef)) + [void]($members.AppendChild($MemberType)) } #foreach extension [void]($main.AppendChild($members)) @@ -242,7 +241,7 @@ Created $(Get-Date) $out = Convert-Path $path if ($PSCmdlet.ShouldProcess($out)) { $doc.save($out) - } #end Whatif + } #end WhatIf } #else } #if ps1xml elseif ($path -match "\.xml$") { @@ -255,10 +254,10 @@ Created $(Get-Date) } } #if valid path - if ($Passthru) { + if ($PassThru) { Get-Item -Path $Path } - Write-Verbose "Ending: $($MyInvocation.Mycommand)" + Write-Verbose "Ending: $($MyInvocation.MyCommand)" } } #end Export-PSTypeExtension diff --git a/functions/Get-PSType.ps1 b/functions/Get-PSType.ps1 index 3c10f05..8d01a3f 100644 --- a/functions/Get-PSType.ps1 +++ b/functions/Get-PSType.ps1 @@ -1,26 +1,26 @@ Function Get-PSType { - [cmdletbinding()] - [outputtype("System.String")] + [CmdletBinding()] + [OutputType("System.String")] Param( [Parameter( Position = 0, Mandatory, ValueFromPipeline )] - [object]$Inputobject + [object]$InputObject ) Begin { - Write-Verbose "Starting: $($MyInvocation.Mycommand)" + Write-Verbose "Starting: $($MyInvocation.MyCommand)" $data = @() } Process { #get the type of each pipelined object - $data += ($Inputobject | Get-Member | Select-Object -First 1).typename + $data += ($InputObject | Get-Member | Select-Object -First 1).TypeName } End { #write unique values to the pipeline $data | Get-Unique - Write-Verbose "Ending: $($MyInvocation.Mycommand)" + Write-Verbose "Ending: $($MyInvocation.MyCommand)" } -} #end Get-PSType \ No newline at end of file +} #end Get-PSType diff --git a/functions/Get-PSTypeExtension.ps1 b/functions/Get-PSTypeExtension.ps1 index 820ee38..3354d93 100644 --- a/functions/Get-PSTypeExtension.ps1 +++ b/functions/Get-PSTypeExtension.ps1 @@ -1,110 +1,109 @@ Function Get-PSTypeExtension { - [cmdletbinding()] - [outputtype("PSTypeExtension")] + [CmdletBinding()] + [OutputType('PSTypeExtension')] Param( [Parameter( Position = 0, Mandatory, - HelpMessage = "Enter the name of type like System.IO.FileInfo", + HelpMessage = 'Enter the name of type like System.IO.FileInfo', ValueFromPipelineByPropertyName, ValueFromPipeline )] - [ValidateNotNullorEmpty()] - [string]$TypeName, + [ValidateNotNullOrEmpty()] + [String]$TypeName, [Parameter( - HelpMessage = "Enter a comma separated list of member names", - ParameterSetName = "members" + HelpMessage = 'Enter a comma separated list of member names', + ParameterSetName = 'members' )] [string[]]$Members, - [Parameter(HelpMessage = "Show CodeProperty custom properties")] - [switch]$CodeProperty - + [Parameter(HelpMessage = 'Show CodeProperty custom properties')] + [Switch]$CodeProperty ) Begin { - Write-Verbose "Starting: $($MyInvocation.Mycommand)" - $typedata = @() + Write-Verbose "Starting: $($MyInvocation.MyCommand)" + $TypeData = @() } #begin Process { - Write-Verbose "Converting typename to proper type" + Write-Verbose 'Converting TypeName to proper type' $TypeName = _convertTypeName $TypeName - Write-Verbose "Analyzing $typename" + Write-Verbose "Analyzing $TypeName" if ($TypeName) { - Write-Verbose "Getting type data" - $typedata += Get-TypeData -TypeName $typename + Write-Verbose 'Getting type data' + $TypeData += Get-TypeData -TypeName $TypeName } else { - Write-Warning "Failed to get a typename" + Write-Warning 'Failed to get a TypeName' #bail out - $typedata = $False + $TypeData = $False return } } #process End { - if ($typedata) { - $typedata = $typedata | Select-Object -Unique + if ($TypeData) { + $TypeData = $TypeData | Select-Object -Unique $out = [System.Collections.Generic.List[object]]::new() if (-Not $Members) { - Write-Verbose "Getting all member names" - $Members = $typedata.members.keys + Write-Verbose 'Getting all member names' + $Members = $TypeData.members.keys } foreach ($name in $Members) { Try { Write-Verbose "Analyzing member $name" - $member = $typedata.members[$name] - $datatype = $member.gettype().name + $member = $TypeData.members[$name] + $datatype = $member.GetType().name Write-Verbose "Processing type $datatype" Switch ($datatype) { - "AliasPropertyData" { - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' - MemberType = "AliasProperty" + 'AliasPropertyData' { + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' + MemberType = 'AliasProperty' MemberName = $member.name Value = $member.ReferencedMemberName - Typename = $TypeName + TypeName = $TypeName } } #alias - "ScriptpropertyData" { + 'ScriptPropertyData' { if ($member.GetScriptBlock) { $code = $member.GetScriptBlock.ToString() } else { $code = $member.SetScriptBlock.ToString() } - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' - MemberType = "ScriptProperty" + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' + MemberType = 'ScriptProperty' MemberName = $member.name Value = $code - Typename = $TypeName + TypeName = $TypeName } } #scriptproperty - "ScriptMethodData" { - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' - MemberType = "ScriptMethod" + 'ScriptMethodData' { + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' + MemberType = 'ScriptMethod' MemberName = $member.name Value = $member.script.ToString().trim() - Typename = $TypeName + TypeName = $TypeName } } #scriptmethod - "NotePropertyData" { - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' - MemberType = "Noteproperty" + 'NotePropertyData' { + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' + MemberType = 'NoteProperty' MemberName = $member.name Value = $member.Value - Typename = $TypeName + TypeName = $TypeName } - } #noteproperty - "CodePropertyData" { + } #NoteProperty + 'CodePropertyData' { #only show these if requested with -CodeProperty if ($CodeProperty) { if ($member.GetCodeReference) { @@ -113,12 +112,12 @@ Function Get-PSTypeExtension { else { $code = $member.SetCodeReference.ToString() } - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' - MemberType = "CodeProperty" + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' + MemberType = 'CodeProperty' MemberName = $member.name Value = $code - Typename = $TypeName + TypeName = $TypeName } } else { @@ -126,13 +125,13 @@ Function Get-PSTypeExtension { } } #codeproperty Default { - Write-Warning "Cannot process $datatype type for $($typedata.typename)." - $def = [pscustomobject]@{ - PSTypename = 'PSTypeExtension' + Write-Warning "Cannot process $datatype type for $($TypeData.TypeName)." + $def = [PSCustomObject]@{ + PSTypeName = 'PSTypeExtension' MemberType = $datatype MemberName = $member.name Value = $member.Value - Typename = $TypeName + TypeName = $TypeName } } } @@ -151,9 +150,9 @@ Function Get-PSTypeExtension { $out | Sort-Object -Property MemberType, Name } else { - Write-Warning "Failed to find any type extensions for [$Typename]." + Write-Warning "Failed to find any type extensions for [$TypeName]." } - Write-Verbose "Ending: $($MyInvocation.Mycommand)" + Write-Verbose "Ending: $($MyInvocation.MyCommand)" } -} #end Get-PSTypeExtension \ No newline at end of file +} #end Get-PSTypeExtension diff --git a/functions/Import-PSTypeExtension.ps1 b/functions/Import-PSTypeExtension.ps1 index d2c5d35..cd6eef9 100644 --- a/functions/Import-PSTypeExtension.ps1 +++ b/functions/Import-PSTypeExtension.ps1 @@ -8,12 +8,12 @@ Function Import-PSTypeExtension { HelpMessage = "The name of the imported file. The extension must be .xml or .json")] [ValidatePattern("\.(xml|json)$")] [ValidateScript( { Test-Path $(Convert-Path $_) })] - [alias("fullname")] - [string]$Path + [alias("FullName")] + [String]$Path ) Begin { - Write-Verbose "Starting: $($myInvocation.mycommand)" + Write-Verbose "Starting: $($MyInvocation.MyCommand)" } Process { Write-Verbose "Importing file $(Convert-Path $Path)" @@ -38,14 +38,14 @@ Function Import-PSTypeExtension { $value = $item.Value } #add a custom -WhatIf message - if ($PSCmdlet.ShouldProcess($Item.typename, "Adding $($item.membertype) $($item.MemberName)")) { + if ($PSCmdlet.ShouldProcess($Item.TypeName, "Adding $($item.MemberType) $($item.MemberName)")) { #implement the change - Update-TypeData -TypeName $item.Typename -MemberType $item.MemberType -MemberName $item.MemberName -Value $value -Force + Update-TypeData -TypeName $item.TypeName -MemberType $item.MemberType -MemberName $item.MemberName -Value $value -Force } } #foreach } End { - Write-Verbose "Ending: $($myInvocation.mycommand)" + Write-Verbose "Ending: $($MyInvocation.MyCommand)" } -} #end Import-PSTypeExtension \ No newline at end of file +} #end Import-PSTypeExtension diff --git a/functions/New-PSPropertySet.ps1 b/functions/New-PSPropertySet.ps1 index 5331c63..91a6896 100644 --- a/functions/New-PSPropertySet.ps1 +++ b/functions/New-PSPropertySet.ps1 @@ -1,27 +1,27 @@ Function New-PSPropertySet { - [cmdletbinding(SupportsShouldProcess, DefaultParameterSetName = "new")] + [CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = "new")] Param( - [Parameter(Position = 0, Mandatory, HelpMessage = "Enter the object typename.")] + [Parameter(Position = 0, Mandatory, HelpMessage = "Enter the object TypeName.")] [ValidateNotNullOrEmpty()] - [string]$Typename, + [String]$TypeName, [Parameter(Mandatory, HelpMessage = "Enter the new property set name. It should be alphanumeric.")] [ValidatePattern("^\w+$")] - [string]$Name, + [String]$Name, [Parameter(Mandatory, HelpMessage = "Enter the existing property names or aliases to belong to this property set.")] [ValidateNotNullOrEmpty()] [string[]]$Properties, [Parameter(Mandatory, HelpMessage = "Enter the name of the .ps1xml file to create.")] [ValidatePattern("\.ps1xml$")] - [string]$FilePath, + [String]$FilePath, [Parameter(HelpMessage = "Append to an existing file.", ParameterSetName = "append")] - [switch]$Append, + [Switch]$Append, [Parameter(HelpMessage = "Don't overwrite an existing file.", ParameterSetName = "new")] - [switch]$NoClobber + [Switch]$NoClobber ) Begin { - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Starting $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Starting $($MyInvocation.MyCommand)" - Write-Verbose "[$((Get-Date).TimeofDay) BEGIN ] Set typename $typename to proper case" + Write-Verbose "[$((Get-Date).TimeOfDay) BEGIN ] Set TypeName $TypeName to proper case" $TypeName = _convertTypeName $TypeName $settings = [System.Xml.XmlWriterSettings]::new() @@ -41,29 +41,29 @@ Created $(Get-Date) } #begin Process { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a property set called $Name for $Typename" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating a property set called $Name for $TypeName" #convert file path to a true file system path. $cPath = Join-Path -Path (Convert-Path (Split-Path $filepath)) -ChildPath (Split-Path $FilePath -Leaf) if ($Append -AND (-Not (Test-Path $FilePath))) { Write-Warning "Failed to find $Filepath for appending." - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Ending $($MyInvocation.MyCommand)" #bail out return } elseif ($Append) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Appending to $filepath" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Appending to $filepath" [xml]$doc = Get-Content $cPath - $members = $doc.types.SelectNodes("Type[Name='$typeName']").Members + $members = $doc.types.SelectNodes("Type[Name='$TypeName']").Members if ($members) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Appending to existing typename entry" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Appending to existing TypeName entry" } else { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a new typename entry" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating a new TypeName entry" $newType = $doc.CreateNode("element", "Type", $null) $tName = $doc.CreateElement("Name") - $tName.InnerText = $typename - [void]($newType.AppendChild($tname)) + $tName.InnerText = $TypeName + [void]($newType.AppendChild($tName)) $members = $doc.CreateNode("element", "Members", $null) $IsNewType = $True } @@ -71,26 +71,26 @@ Created $(Get-Date) $propSet = $doc.CreateNode("element", "PropertySet", $null) $eName = $doc.CreateElement("Name") $eName.InnerText = $Name - [void]($propset.AppendChild($eName)) + [void]($propSet.AppendChild($eName)) $ref = $doc.CreateNode("element", "ReferencedProperties", $null) foreach ($item in $properties) { $prop = $doc.CreateElement("Name") - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding property $item" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding property $item" $prop.InnerText = $item [void]($ref.AppendChild($prop)) } - [void]($propset.AppendChild($ref)) - [void]($members.AppendChild($propset)) + [void]($propSet.AppendChild($ref)) + [void]($members.AppendChild($propSet)) - if ($IsnewType) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Appending new type" + if ($IsNewType) { + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Appending new type" [void]($newType.AppendChild($members)) - [void]($doc.types.AppendChild($newtype)) + [void]($doc.types.AppendChild($newType)) } } #else append else { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Creating a new XML document" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Creating a new XML document" <# use a random temp name to create the xml file. At the end of the process copy the temp file to the specified file path. This makes it possible to use -WhatIf @@ -104,52 +104,52 @@ Created $(Get-Date) $doc.WriteStartElement("Types") $doc.WriteStartElement("Type") - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Defining type as $Typename" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Defining type as $TypeName" $doc.WriteElementString("Name", $TypeName) $doc.WriteStartElement("Members") $doc.WriteStartElement("PropertySet") #the property set name - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Defining property set name $Name" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Defining property set name $Name" $doc.WriteElementString("Name", $Name) $doc.WriteStartElement("ReferencedProperties") foreach ($item in $properties) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Adding property $item" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Adding property $item" $doc.WriteElementString("Name", $item) } #end type - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Closing and saving file." + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Closing and saving file." $doc.WriteEndElement() $doc.WriteEndDocument() $doc.Close() $doc.Dispose() } - if ($PSCmdlet.ShouldProcess($cpath)) { + if ($PSCmdlet.ShouldProcess($cPath)) { if ((-Not $Append) -AND (Test-Path $tmpFile)) { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Copying temp file to $cpath" + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Copying temp file to $cPath" - if ($NoClobber -AND (Test-Path $cpath)) { - Write-Warning "The file $cpath exists and NoClobber was specified." + if ($NoClobber -AND (Test-Path $cPath)) { + Write-Warning "The file $cPath exists and NoClobber was specified." } else { - Copy-Item -Path $tmpFile -Destination $cpath + Copy-Item -Path $tmpFile -Destination $cPath } #always clean up the temp file Remove-Item -Path $tmpFile -WhatIf:$false -ErrorAction SilentlyContinue } else { - Write-Verbose "[$((Get-Date).TimeofDay) PROCESS] Saving to $cpath" - $doc.Save($cpath) + Write-Verbose "[$((Get-Date).TimeOfDay) PROCESS] Saving to $cPath" + $doc.Save($cPath) } } } #process End { - Write-Verbose "[$((Get-Date).TimeofDay) END ] Ending $($myinvocation.mycommand)" + Write-Verbose "[$((Get-Date).TimeOfDay) END ] Ending $($MyInvocation.MyCommand)" } #end -} #close New-PSPropertySet \ No newline at end of file +} #close New-PSPropertySet diff --git a/functions/private.ps1 b/functions/private.ps1 index 730ef7e..c4f2d9b 100644 --- a/functions/private.ps1 +++ b/functions/private.ps1 @@ -1,19 +1,19 @@ Function _convertTypeName { [CmdletBinding()] - Param([string]$Typename) + Param([String]$TypeName) Try { #this code should never really throw an exception $ErrorActionPreference = "Stop" - $tn = $Typename -as [type] + $tn = $TypeName -as [type] if ($tn) { - $tn.Fullname + $tn.FullName } else { - $Typename + $TypeName } } Catch { - $typename + $TypeName } -} \ No newline at end of file +} diff --git a/samples/cimlogicaldisk-extensions.json b/samples/cimlogicaldisk-extensions.json index 439cf99..9acb366 100644 --- a/samples/cimlogicaldisk-extensions.json +++ b/samples/cimlogicaldisk-extensions.json @@ -16,5 +16,5 @@ "MemberName": "PctFree", "Value": "[math]::round(($this.freespace/$this.size)*100,2)", "TypeName": "Microsoft.Management.Infrastructure.CimInstance#root/cimv2/Win32_LogicalDisk" - } + } ]