Skip to content

Commit 37833f9

Browse files
v2.24.0
1 parent 7a4071f commit 37833f9

39 files changed

+2377
-194
lines changed

PSScriptTools.psd1

334 Bytes
Binary file not shown.

PSScriptTools.psm1

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Get-ChildItem -path $PSScriptRoot\functions\*.ps1 | ForEach-Object -process {
99
. $_.FullName
1010
}
1111

12-
#define the global PSAnsiFileMap variable
12+
Write-Verbose "Define the global PSAnsiFileMap variable"
1313
$json = "psansifilemap.json"
1414
#test for user version
1515
$userjson = Join-Path -path $HOME -ChildPath $json
@@ -24,7 +24,34 @@ else {
2424

2525
Set-Variable -Name PSAnsiFileMap -value (Get-Content -path $map | ConvertFrom-Json) -Scope Global
2626

27-
#add ToDo options to the ISE or VS Code
27+
Write-Verbose "Define special character map"
28+
$global:PSSpecialChar = @{
29+
FullBlock = ([char]0x2588)
30+
LightShade = ([char]0x2591)
31+
MediumShade = ([char]0x2592)
32+
DarkShade = ([char]0x2593)
33+
BlackSquare = ([char]0x25A0)
34+
WhiteSquare = ([char]0x25A1)
35+
BlackSmallSquare = ([char]0x25AA)
36+
WhiteSmallSquare = ([char]0x25AB)
37+
UpTriangle = ([char]0x25B2)
38+
DownTriangle = ([char]0x25BC)
39+
Lozenge = ([char]0x25CA)
40+
WhiteCircle = ([char]0x25CB)
41+
BlackCircle = ([char]0x25CF)
42+
WhiteFace = ([char]0x263A)
43+
BlackFace = ([char]0x263B)
44+
SixPointStar = ([char]0x2736)
45+
Diamond = ([char]0x2666)
46+
Club = ([char]0x2663)
47+
Heart = ([char]0x2665)
48+
Spade = ([char]0x2660)
49+
}
50+
51+
Write-Verbose "Defining the variable `$PSSamplePath to the samples folder for this module"
52+
$global:PSSamplePath = Join-Path -path $PSScriptroot -ChildPath Samples
53+
54+
Write-Verbose "Add ToDo options to the ISE or VS Code"
2855
if ($psEditor) {
2956
#This may not be working in newer versions of the PowerShell extension under PowerShell 7
3057
Write-Verbose "Defining VSCode additions"
@@ -35,7 +62,7 @@ if ($psEditor) {
3562

3663
$prompt = "What do you need to do?"
3764
$title = "To Do"
38-
$item = Invoke-Inputbox -Title $title -Prompt $prompt
65+
$item = Invoke-InputBox -Title $title -Prompt $prompt
3966
$todo = "# [$(Get-Date)] TODO: $item"
4067
$context.CurrentFile.InsertText($todo)
4168
}
@@ -55,7 +82,7 @@ elseif ($psise) {
5582
$action = {
5683
$prompt = "What do you need to do?"
5784
$title = "To Do"
58-
$item = Invoke-Inputbox -Title $title -Prompt $prompt
85+
$item = Invoke-InputBox -Title $title -Prompt $prompt
5986
$todo = "# [$(Get-Date)] TODO: $item"
6087
$psise.CurrentFile.Editor.InsertText($todo)
6188
#jump cursor to the end

README.md

Lines changed: 94 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
[![PSGallery Version](https://img.shields.io/powershellgallery/v/PSScripttools.png?style=for-the-badge&logo=powershell&label=PowerShell%20Gallery)](https://www.powershellgallery.com/packages/PSScripttools/) [![PSGallery Downloads](https://img.shields.io/powershellgallery/dt/PSScripttools.png?style=for-the-badge&label=Downloads)](https://www.powershellgallery.com/packages/PSScripttools/)
44

5-
This PowerShell module contains a number of functions you might use to enhance your own functions and scripts. The [Samples](./samples) folder contains demonstration script files.
5+
This module contains a collection of functions, variables and format files that you can use to enhance your PowerShell scripting work. Or get more done from a PowerShell prompt with less typing. Most of the commands are designed to work cross-platform.
66

77
## Current Release
88

@@ -51,8 +51,7 @@ PS C:\> Get-ModuleCommand PSCalendar
5151
Show-GuiCalendar gcal Function Display a WPF-based calendar
5252
```
5353

54-
Get module commands using the default formatted view.
55-
There is also a default view for `Format-List`.
54+
Get module commands using the default formatted view. There is also a default view for `Format-List`.
5655

5756
### [Get-PSScriptTools](docs/Get-PSScriptTools.md)
5857

@@ -324,6 +323,10 @@ ExecutionPolicy : RemoteSigned
324323
Culture : English (United States)
325324
```
326325

326+
You can also turn this into a text block using the `AsString` parameter. This is helpful when you want to include the output in some type of report.
327+
328+
![PSWho Report](images/add-border-ansi2.png)
329+
327330
### [Find-CimClass](docs/Find-CimClass.md)
328331

329332
This function is designed to search an entire CIM repository for a class name. Sometimes, you may have a guess about a class name but not know the full name or even the correct namespace. `Find-CimClass` will recursively search for a given classname. You can use wildcards and search remote computers.
@@ -392,6 +395,25 @@ You can also get detailed information.
392395

393396
Results will vary depending on whether you are running PowerShell on Windows nor non-Windows systems.
394397

398+
### [Get-PathVariable](docs/Get-PathVariable.md)
399+
400+
Over time, as you add and remove programs, your `%PATH%` might change. An application may add a location but not remove it when you uninstall the application. This command makes it easier to identify locations and whether they are still good.
401+
402+
```powershell
403+
PS C:\> Get-PathVariable
404+
405+
Scope UserName Path Exists
406+
----- -------- ---- ------
407+
User Jeff C:\Program Files\kdiff3 True
408+
User Jeff C:\Program Files (x86)\Bitvise SSH Client True
409+
User Jeff C:\Program Files\OpenSSH True
410+
User Jeff C:\Program Files\Intel\WiFi\bin\ True
411+
User Jeff C:\Program Files\Common Files\Intel\WirelessCommon\ True
412+
User Jeff C:\Users\Jeff\AppData\Local\Programs\Microsoft VS Code\bin True
413+
User Jeff C:\Program Files (x86)\Vale\ True
414+
...
415+
```
416+
395417
## File Tools
396418

397419
### [Test-EmptyFolder](docs/Test-EmptyFolder.md)
@@ -1125,6 +1147,50 @@ C:\work\Alpha\
11251147

11261148
This example is using parameter and command aliases. You can display a tree listing with files including user specified properties. Use a value of * to show all properties.
11271149

1150+
### [New-ANSIBar](docs/New-ANSIBar.md)
1151+
1152+
You can use this command to create colorful bars using ANSI escape sequences based on a 256 color scheme. The default behavior is to create a gradient bar that goes from first to last values in the range and then back down again. Or you can create a single gradient that runs from the beginning of the range to the end. You can use one of the default characters or specify a custom one.
1153+
1154+
![New-ANSIBar](images/ansibar.png)
1155+
1156+
### [New-RedGreenGradient](docs/New-RedGreenGradient.md)
1157+
1158+
A related command is `New-RedGreenGradient` which displays a bar going from red to green. This might be handy when you want to present a visual indicator.
1159+
1160+
![New-RedGreenGradient](images/redgreen.png)
1161+
1162+
### [Write-ANSIProgress](docs/Write-ANSIProgress.md)
1163+
1164+
You could also use `Write-ANSIProgress` to show a custom ANSI bar.
1165+
1166+
![Write-ANSIProgress simple](images/write-ansprogress-1.png)
1167+
1168+
![write-ANSIProgress in code](images/write-ansprogress-2.png)
1169+
1170+
Or you can use it in your code to display a console progress bar.
1171+
1172+
```powershell
1173+
$sb = {
1174+
Clear-Host
1175+
$top = Get-ChildItem c:\scripts -Directory
1176+
$i = 0
1177+
$out=@()
1178+
$pos = $host.ui.RawUI.CursorPosition
1179+
Foreach ($item in $top) {
1180+
$i++
1181+
$pct = [math]::round($i/$top.count,2)
1182+
Write-ANSIProgress -PercentComplete $pct -position $pos
1183+
Write-Host " Processing $(($item.fullname).padright(80))" -ForegroundColor Yellow -NoNewline
1184+
$out+= Get-ChildItem -path $item -Recurse -file | Measure-Object -property length -sum |
1185+
Select-Object @{Name="Path";Expression={$item.fullname}},Count,@{Name="Size";Expression={$_.Sum}}
1186+
}
1187+
Write-Host ""
1188+
$out | Sort-object -property Size -Descending
1189+
}
1190+
```
1191+
1192+
![Write-ANSIProgress script](images/write-ansprogress-3.png)
1193+
11281194
## Format-Functions
11291195

11301196
A set of simple commands to make it easier to format values.
@@ -1385,7 +1451,7 @@ You will need to manually install the file.
13851451

13861452
## Other
13871453

1388-
From time to time I will include additional items that you might find useful. One item that you get when you import this module is a custom format.ps1xml file for services. If you are running PowerShell 7, you can run `Get-Service` and pipe it to the table view.
1454+
From time to time I will include additional items that you might find useful. One item that you get when you import this module is a custom format.ps1xml file for services. You can run `Get-Service` and pipe it to the table view.
13891455

13901456
```powershell
13911457
PS C:\> Get-Service | Format-Table -view ansi
@@ -1395,6 +1461,8 @@ This will display the service status color-coded.
13951461

13961462
![ServiceAnsi](images/serviceansi.png)
13971463

1464+
This will not work in the PowerShell ISE as it is not ANSI aware.
1465+
13981466
### PSAnsiMap
13991467

14001468
I have done something similar for output from `Get-ChildItem`. The module includes json file that is exported as a global variable called `PSAnsiFileMap`.
@@ -1417,7 +1485,7 @@ ChildContainer
14171485

14181486
The map includes ANSI settings for different file types. You won't see the ANSI value in the output. The module will add a custom table view called `ansi` which you can use to display file results colorized in PowerShell 7.
14191487

1420-
![](images/ansi-file-format.png)
1488+
![ANSI File listing](images/ansi-file-format.png)
14211489

14221490
The mapping file is user customizable. Copy the `psansifilemap.json` file from the module's root directory to $HOME. When you import this module, if the file is found, it will be imported and used as `psansifilemap`, otherwise the module's file will be used.
14231491

@@ -1475,6 +1543,26 @@ The file will look like this:
14751543

14761544
You can create or modify file groups. The Pattern value should be a regular expression pattern to match on the filename. Don't forget you will need to escape characters for the json format. The Ansi value will be an ANSI escape sequence. You can use `\u001b` for the \``e` character.
14771545

1546+
### PSSpecialChar
1547+
1548+
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 ones you also use.
1549+
1550+
![PSSpecialChar](images/psspecialchar.png)
1551+
1552+
The names are the same as used in CharMap.exe. Don't let the naming confuse you. It may say `BlackSquare` but the color will depend on how you use it.
1553+
1554+
```powershell
1555+
Get-WindowsVersionString | Add-Border -border $PSSpecialChar.BlackSmallSquare -ANSIBorder "$([char]0x1b)[38;5;214m"
1556+
```
1557+
1558+
![PSSpecialChar Border](images/psspecialchar-border.png)
1559+
1560+
### Sample scripts
1561+
1562+
This PowerShell module contains a number of functions you might use to enhance your own functions and scripts. The [Samples](./samples) folder contains demonstration script files. You can access the folder in PowerShell using the `$PSSamplePath`. 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.
1563+
1564+
![ProcessPercent.ps1](images/processpercent.png)
1565+
14781566
## Related Modules
14791567

14801568
If you find this module useful, you might also want to look at my tools for [creating and managing custom type extensions](https://github.com/jdhitsolutions/PSTypeExtensionTools), [managing scheduled jobs](https://github.com/jdhitsolutions/ScheduledJobTools) and [running remote commands outside of PowerShell Remoting](https://github.com/jdhitsolutions/PSRemoteOperations).
@@ -1483,4 +1571,4 @@ If you find this module useful, you might also want to look at my tools for [cre
14831571

14841572
Where possible these commands have been tested with PowerShell 7, but not every platform. If you encounter problems, have suggestions or other feedback, please post an [issue](https://github.com/jdhitsolutions/PSScriptTools/issues). It is assumed you will __not__ be running this commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
14851573

1486-
> Last Updated *2020-05-14 18:42:52Z UTC*
1574+
> Last Updated *2020-05-21 20:11:54Z UTC*

changelog.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,43 @@
11
# Change Log for PSScriptTools
22

3+
## v2.24.0
4+
5+
### Add
6+
7+
+ Added parameter alias of `tb` for `-TextBlock` in `Add-Border`.
8+
+ Added parameter alias of `border` for `-Character` in `Add-Border`.
9+
+ Added `New-ANSIBar` command.
10+
+ Added `New-RedGreenGradient` command.
11+
+ Added `Write-ANSIProgress` command with an alias of `wap`.
12+
+ Defined a global variable called `$PSSpecialChar` which is a hash table select special characters you might want to use with `Add-Border` or `New-AnsiBar`.
13+
+ Added a table view to `modulecommand.format.ps1xml` and made it the default.
14+
+ Added a new table view called `verb` to `modulecommand.format.ps1xml`.
15+
+ Added `Get-PathVariable` with its own custom format file. (Issue #74)
16+
+ Added sample script `Get-Status.ps1`.
17+
+ Added global variable `$PSSamplePath` to point to the sample script location
18+
19+
### Change
20+
21+
+ Modified `Add-Border` to adjust line length when ANSI escapes are part of the text. (Issue #79)
22+
+ Modified `Get-PSWho` to trim when using `-AsString`.
23+
+ Fixed bug in `New-PSFormatXML` what was writing an XML element to the pipeline when using `-Wrap`.
24+
+ Updated `Get-ModuleCommand` output to include the module name.
25+
+ Updated `serviceansi.format.ps1xml` and `filesystem-ansi.format.ps1xml` to use an escape sequence available to both Windows PowerShell and PowerShell 7.
26+
+ Fixed wrong type name in `serviceansi.format.ps1xml`.
27+
+ Help updates.
28+
+ Updated sample scripts.
29+
+ Updated `README.md`.
30+
31+
### Delete
32+
33+
+ Removed duplicate line of code in `New-PSFormatXML`.
34+
335
## v2.23.0
436

537
+ Updated `New-PSFormatXML` to include an option to wrap tables. (Issue #78)
638
+ Updated `Add-Border` to include parameters to specify an ANSI sequence for the border and one for the text.
739
+ Revised `Add-Border` to better support inserting blank lines.
8-
+ Updated `README.md`
40+
+ Updated `README.md`.
941

1042
## v2.22.0
1143

docs/Add-Border.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ PS C:\> add-border -Text $t -ANSIBorder "$([char]0x1b)[38;5;47m" -ANSIText "$([c
9898

9999
This will write a color version of the text and border. You would this type of ANSI syntax for Windows PowerShell. In PowerShell 7, you can use the same syntax or the much easier "`e[38;5;47m".
100100

101+
### EXAMPLE 6
102+
103+
```powershell
104+
PS C:\scripts> add-border -textblock (Get-PSWho -AsString ).trim() -ANSIBorder "`e[38;5;214m" -Character ([char]0x25CA) -ANSIText "`e[38;5;225m"
105+
106+
◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
107+
◊ User : BOVINE320\Jeff ◊
108+
◊ Elevated : True ◊
109+
◊ Computername : BOVINE320 ◊
110+
◊ OperatingSystem : Microsoft Windows 10 Pro [64-bit] ◊
111+
◊ OSVersion : 10.0.18363 ◊
112+
◊ PSVersion : 7.0.1 ◊
113+
◊ Edition : Core ◊
114+
◊ PSHost : ConsoleHost ◊
115+
◊ WSMan : 3.0 ◊
116+
◊ ExecutionPolicy : RemoteSigned ◊
117+
◊ Culture : English (United States) ◊
118+
◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊◊
119+
```
120+
121+
This example requires PowerShell 7 because of the escape sequence.
122+
101123
## PARAMETERS
102124

103125
### -Text
@@ -123,7 +145,7 @@ A multi-line block of text. You might want to trim blank lines from the beginnin
123145
```yaml
124146
Type: String[]
125147
Parameter Sets: block
126-
Aliases:
148+
Aliases: tb
127149

128150
Required: True
129151
Position: 1
@@ -139,7 +161,7 @@ The character to use for the border. It must be a single character.
139161
```yaml
140162
Type: String
141163
Parameter Sets: (All)
142-
Aliases:
164+
Aliases: border
143165

144166
Required: False
145167
Position: Named

0 commit comments

Comments
 (0)