Skip to content

Commit f0aef37

Browse files
v2.38.0
1 parent da3b2a8 commit f0aef37

29 files changed

+2057
-1490
lines changed

Archive-ChangeLog.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,23 @@
22

33
This file contains older change history. It is maintained for reference purposes.
44

5+
## v2.34.0
6+
7+
+ Fixed typo bug in `Get-PSScriptTools` that was failing to get command aliases. ([Issue #99](https://github.com/jdhitsolutions/PSScriptTools/issues/99))
8+
+ Modified `Get-PSScriptTools` to improve performance. Assuming that all exported functions are using standard verbs.
9+
+ Added `Get-PSAnsiFileMap`.
10+
+ Added `Set-PSAnsiFileMapEntry`.
11+
+ Added `Remove-PSAnsiFileMapEntry`.
12+
+ Added `Export-PSAnsiFileMap`.
13+
+ Added `Show-ANSISequence`.
14+
+ Updated `filesystem.ansi.format.ps1xml` to use last matching pattern.
15+
+ Modified `Show-Tree` to better handle piped-in file and directory objects.
16+
+ Added an alias `ab` for `Add-Border`.
17+
+ Added an alias of `nab` for `New-AnsiBar`.
18+
+ Updated `README.md`.
19+
+ Updated module description.
20+
+ Help updates.
21+
522
## v2.33.1
623

724
+ Fixed bug in `ConvertTo-WPFGrid` with refresh and timeout values. (Issue #98)

PSScriptTools.psd1

-6.09 KB
Binary file not shown.

PSScriptTools.psm1

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ if ($psEditor) {
8787
$prompt = "What do you need to do?"
8888
$title = "To Do"
8989
$item = Invoke-InputBox -Title $title -Prompt $prompt
90-
$todo = "# [$(Get-Date)] TODO: $item"
90+
$todo = "# TODO: $item [$(Get-Date)]"
9191
$context.CurrentFile.InsertText($todo)
9292
}
9393
$rParams = @{
@@ -97,7 +97,31 @@ if ($psEditor) {
9797
SuppressOutput = $false
9898
}
9999
Register-EditorCommand @rParams
100-
}
100+
101+
Write-Verbose "Adding Set-LocationToFile"
102+
Function Set-LocationToFile {
103+
#set location to directory of current file
104+
[CmdletBinding()]
105+
[alias("sd", "jmp")]
106+
[outputtype("none")]
107+
Param ()
108+
109+
if ($host.name -match "Code") {
110+
111+
$context = $psEditor.GetEditorContext()
112+
$thispath = $context.CurrentFile.Path
113+
$target = Split-Path -Path $thispath
114+
Write-Verbose "Using $thispath"
115+
Write-Verbose "Changing to $target"
116+
Set-Location -Path $target
117+
118+
Clear-Host
119+
}
120+
else {
121+
Write-Warning "This command must be run in the VS Code integrated PowerShell terminal."
122+
}
123+
}
124+
} #VSCode
101125
elseif ($psise) {
102126
Write-Verbose "Defining ISE additions"
103127

@@ -115,8 +139,26 @@ elseif ($psise) {
115139
#add the action to the Add-Ons menu
116140
$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("ToDo", $Action, "Ctrl+Alt+2" ) | Out-Null
117141
}
142+
143+
Function Set-LocationToFile {
144+
[cmdletbinding()]
145+
[alias("sd","jmp")]
146+
[OutputType("none")]
147+
Param()
148+
149+
if ($host.name -match "ISE") {
150+
151+
$path = Split-Path -Path $psISE.CurrentFile.FullPath
152+
set-location -path $path
153+
clear-host
154+
}
155+
Else {
156+
Write-Warning "This command must be run the the PowerShell ISE."
157+
}
158+
}
118159
}
119160

161+
120162
#define a function to open the PDF version of the README and other documentation
121163
Function Open-PSScriptToolsHelp {
122164
[cmdletbinding()]

PSScriptToolsManual.pdf

15.3 KB
Binary file not shown.

README.md

Lines changed: 120 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The contents of this file and other documentation can be viewed using the `Open-
1515
+ [Installation](#Installation)
1616
+ [General Tools](#General-Tools)
1717
+ [File Tools](#File-Tools)
18-
+ [ToDo](#ToDo)
18+
+ [Editor Integrations](#Editor-Integrations)
1919
+ [Graphical Tools](#Graphical-Tools)
2020
+ [Hashtable Tools](#Hashtable-Tools)
2121
+ [Select Functions](#Select-Functions)
@@ -431,7 +431,7 @@ PS C:\> Get-MyVariable
431431
NName Value Type
432432
---- ----- ----
433433
a bits ServiceController
434-
dt 10/22/2018 10:49:38 AM DateTime
434+
dt 10/22/2020 10:49:38 AM DateTime
435435
foo 123 Int32
436436
r {1, 2, 3, 4...} Object[]
437437
...
@@ -781,12 +781,16 @@ which generates this markdown:
781781

782782
Because the function writes markdown to the pipeline you will need to pipe it to a command `Out-File` to create a file.
783783

784-
## ToDo
784+
## Editor Integrations
785785

786-
Because this module is intended to make scripting easier for you, it adds options to insert ToDo statements into PowerShell files. If you are using the PowerShell ISE or VS Code and import this module, it will add the capability to insert a line like this:
786+
Because this module is intended to make scripting easier for you, it adds a few editor specific features if you import this module in either the PowerShell ISE or Visual Studio Code. The VS Code features assume you are using the integrated PowerShell terminal.
787+
788+
### Insert ToDo
789+
790+
One such feature is the ability to insert ToDo statements into PowerShell files. If you are using the PowerShell ISE or VS Code and import this module, it will add the capability to insert a line like this:
787791

788792
```dos
789-
# [12/13/2018 16:52:40] TODO: Add parameters
793+
# [12/13/2020 16:52:40] TODO: Add parameters
790794
```
791795

792796
In the PowerShell ISE, you will get a new menu under Add-Ons.
@@ -801,6 +805,17 @@ The comment will be inserted at the current cursor location.
801805

802806
In VS Code, access the command palette (Ctrl+Shift+P) and then `PowerShell: Show Additional Commands from PowerShell Modules`. Select `Insert ToDo` from the list, and you'll get the same input box. Note that this will only work for PowerShell files.
803807

808+
### Set Terminal Location
809+
810+
Another feature is the ability to set your terminal location to match that of the the currently active file. For example, if the current file is located in C:\Scripts\Foo and your terminal location is D:\Temp\ABC, you can quickly jump to the file location.
811+
812+
```dos
813+
PS D:\Temp\ABC\> sd
814+
PS C:\Scripts\Foo\>
815+
```
816+
817+
The full command name is `Set-LocationToFile` but you'll find it easier to use the `sd` or `jmp` aliases. This command will also clear the host.
818+
804819
## Graphical Tools
805820

806821
### [Invoke-InputBox](docs/Invoke-InputBox.md)
@@ -910,11 +925,11 @@ Convert-HashtableString
910925
Name Value
911926
---- -----
912927
CreatedBy BOVINE320\Jeff
913-
CreatedAt 10/02/2018 21:28:47 UTC
928+
CreatedAt 10/02/2020 21:28:47 UTC
914929
Computername Think51
915930
Error
916931
Completed True
917-
Date 10/02/2018 21:29:35 UTC
932+
Date 10/02/2020 21:29:35 UTC
918933
Scriptblock restart-service spooler -force
919934
CreatedOn BOVINE320
920935
```
@@ -1303,7 +1318,7 @@ utc_offset : +11:00
13031318
unixtime : 1552668285
13041319
timezone : Australia/Hobart
13051320
dst_until : 2019-04-06T16:00:00+00:00
1306-
dst_from : 2018-10-06T16:00:00+00:00
1321+
dst_from : 2020-10-06T16:00:00+00:00
13071322
dst : True
13081323
day_of_year : 75
13091324
day_of_week : 6
@@ -1626,6 +1641,46 @@ TotalMemGB FreeMemGB PctFree
16261641

16271642
## Scripting Tools
16281643

1644+
### [Get-PSUnique](docs/Get-PSUnique.md)
1645+
1646+
For the most part, objects you work with in PowerShell are guaranteed to be unique. But you might import data where there is the possibility of duplicate items. Consider this CSV sample.
1647+
1648+
```powershell
1649+
$Obj = "Animal,Snack,Color
1650+
Horse,Quiche,Chartreuse
1651+
Cat,Doritos,Red
1652+
Cat,Pringles,Yellow
1653+
Dog,Doritos,Yellow
1654+
Dog,Doritos,Yellow
1655+
Rabbit,Pretzels,Green
1656+
Rabbit,Popcorn,Green
1657+
Marmoset,Cheeseburgers,Black
1658+
Dog,Doritos,White
1659+
Dog,Doritos,White
1660+
Dog,Doritos,White
1661+
" | ConvertFrom-Csv
1662+
```
1663+
1664+
There are duplicate objects you might want to filter out. For that task, you can use `Get-PSUnique`.
1665+
1666+
```DOS
1667+
PS C:\> $obj | Get-PSUnique | Sort-Object animal
1668+
1669+
1670+
Animal Snack Color
1671+
------ ----- -----
1672+
Cat Pringles Yellow
1673+
Cat Doritos Red
1674+
Dog Doritos White
1675+
Dog Doritos Yellow
1676+
Horse Quiche Chartreuse
1677+
Marmoset Cheeseburgers Black
1678+
Rabbit Popcorn Green
1679+
Rabbit Pretzels Green
1680+
```
1681+
1682+
The duplicate items have been removed. This command works best with simple objects. If your objects have nested object properties, you will need to test if this command can properly filter for unique items.
1683+
16291684
### [Test-IsElevated](docs/Test-IsElevated.md)
16301685

16311686
This simple command will test if the current PowerShell session is running elevated, or as Administrator. On Windows platforms the function uses the .NET Framework to test. On non-Windows platforms, the command tests the user's UID value.
@@ -2011,7 +2066,7 @@ This command is designed to be used within your functions and scripts to make it
20112066

20122067
```dos
20132068
PS C:\> write-detail "Getting file information" -Prefix Process -Date
2014-
9/15/2018 11:42:43 [PROCESS] Getting file information
2069+
9/15/2020 11:42:43 [PROCESS] Getting file information
20152070
```
20162071

20172072
In a script you might use it like this:
@@ -2230,6 +2285,61 @@ In this format view, ReadOnly aliases are displayed in Red.
22302285

22312286
Use [Get-FormatView](docs/Get-FormatView.md) to discover available format views. Or if you'd like to create your own custom views look at [New-PSFormatXML](docs/New-PSFormatXML.md)
22322287

2288+
### Custom Type Extensions
2289+
2290+
When you import the module, you will also get custom type extensions. These are designed to make it easier to work with common objects in PowerShell.
2291+
2292+
#### System.IO.FileInfo
2293+
2294+
The module will extend file objects with the following alias properties:
2295+
2296+
| New Alias | Property |
2297+
| --- | --- |
2298+
| Size | Length |
2299+
| Created | CreationTime |
2300+
| Modified | LastWriteTime |
2301+
2302+
You also have new script properties
2303+
2304+
| Script Property | Description |
2305+
| --- | --- |
2306+
| ModifiedAge | A timespan between the current date the and last write time |
2307+
| CreatedAge | A timespan between the current date the and creation time |
2308+
| SizeKB | The file size formatted in KB to 2 decimal places |
2309+
| SizeMB | The file size formatted in MB to 2 decimal places |
2310+
2311+
```dos
2312+
PS C:\> Get-Childitem C:\work\pswork.xml | Select-Object Name,Size,SizeKB,SizeMB,Created,CreatedAge,Modified,ModifiedAge
2313+
2314+
Name : pswork.xml
2315+
Size : 32072432
2316+
SizeKB : 31320.73
2317+
SizeMB : 30.59
2318+
Created : 1/5/2021 6:46:43 PM
2319+
CreatedAge : 175.17:47:00.4966770
2320+
Modified : 1/6/2021 11:53:20 AM
2321+
ModifiedAge : 175.00:40:23.3527674
2322+
```
2323+
2324+
#### System.Diagnostics.Process
2325+
2326+
The module will extend process objects with a `Runtime` script property.
2327+
2328+
```dos
2329+
PS C:\> Get-Process | Sort-Object runtime -Descending |
2330+
Select-Object -first 5 -Property ID,Name,Runtime
2331+
2332+
Id Name Runtime
2333+
-- ---- -------
2334+
120 Secure System 20:44:51.6139043
2335+
204 Registry 20:44:51.3661961
2336+
4 System 20:44:48.2820565
2337+
704 smss 20:44:48.2726401
2338+
820 csrss 20:44:44.7760844
2339+
```
2340+
2341+
The Idle process will have a null value for this property.
2342+
22332343
### PSSpecialChar
22342344

22352345
A number of the commands in this module can use special characters. To make it easier, when you import the module, it will create a global variable that is a hash table of common special characters. Because it is a hashtable, you can add to it.
@@ -2254,7 +2364,7 @@ This PowerShell module contains several functions you might use to enhance your
22542364
dir $pssamplepath
22552365
```
22562366

2257-
The samples provide suggestions on how you might use some of the commands in this module. The scripts are offered AS-IS and are for demonstration purposes only.
2367+
The samples provide suggestions on how you might use some of the commands in this module. The scripts are offered __AS-IS__ and are for demonstration purposes only.
22582368

22592369
![ProcessPercent.ps1](images/processpercent.png)
22602370

changelog.md

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
This file contains the most recent change history for the PSScriptTools module.
44

5+
## v2.38.0
6+
7+
+ Added `Get-PSUnique` function with an alias of `gpsu`. ([Issue #109](https://github.com/jdhitsolutions/PSScriptTools/issues/109)).
8+
+ Modified `Show-AnsiSequence` to default to `Foreground` when using `-Type` ([Issue #110](https://github.com/jdhitsolutions/PSScriptTools/issues/110)).
9+
+ Cleaned up module manifest.
10+
+ Updated `New-PSFormatXML` to __not__ create the ps1xml file if a bad property is detected ([Issue #111](https://github.com/jdhitsolutions/PSScriptTools/issues/111)).
11+
+ Modified `New-PSFormatXML` to __not__ add an explicit declaration. This means the files will now be saved in the correct UTF-8 format and not UTF-8 with BOM.
12+
+ Modified TODO VSCode command to put date at the end. Otherwise, it breaks the `Better Comments` extension.
13+
+ Added `Set-LocationToFile` which is only loaded when importing the module in VS Code or the PowerShell ISE.
14+
+ Re-saved all `.ps1xml` files as `UTF-8`.
15+
+ Added custom type extension files `fileinfo.types.ps1xml` and `system.diagnostics.process.types.ps1xml`.
16+
+ Updated `README.md`.
17+
518
## v2.37.0
619

720
+ Updated `Convertto-WPFGrid` to better handle non-standard property names. ([Issue #108](https://github.com/jdhitsolutions/PSScriptTools/issues/108)).
@@ -47,23 +60,6 @@ This file contains the most recent change history for the PSScriptTools module.
4760
+ Fixed bug in `Get-ParameterInfo` that failed to display dynamic parameters when using a command alias. ([Issue #101](https://github.com/jdhitsolutions/PSScriptTools/issues/101))
4861
+ Modified format file for `PSParameterInfo` to display `Mandatory` and `IsDynamic` values in color when the value is `$True`.
4962

50-
## v2.34.0
51-
52-
+ Fixed typo bug in `Get-PSScriptTools` that was failing to get command aliases. ([Issue #99](https://github.com/jdhitsolutions/PSScriptTools/issues/99))
53-
+ Modified `Get-PSScriptTools` to improve performance. Assuming that all exported functions are using standard verbs.
54-
+ Added `Get-PSAnsiFileMap`.
55-
+ Added `Set-PSAnsiFileMapEntry`.
56-
+ Added `Remove-PSAnsiFileMapEntry`.
57-
+ Added `Export-PSAnsiFileMap`.
58-
+ Added `Show-ANSISequence`.
59-
+ Updated `filesystem.ansi.format.ps1xml` to use last matching pattern.
60-
+ Modified `Show-Tree` to better handle piped-in file and directory objects.
61-
+ Added an alias `ab` for `Add-Border`.
62-
+ Added an alias of `nab` for `New-AnsiBar`.
63-
+ Updated `README.md`.
64-
+ Updated module description.
65-
+ Help updates.
66-
6763
## Archive
6864

69-
If you need to see older change history, look at the [Archive ChangeLog](https://github.com/jdhitsolutions/PSScriptTools/blob/master/Archive-ChangeLog.md)
65+
If you need to see older change history, look at the [Archive ChangeLog](https://github.com/jdhitsolutions/PSScriptTools/blob/master/Archive-ChangeLog.md) online.

0 commit comments

Comments
 (0)