Skip to content

Commit 53b9d2e

Browse files
v2.19.0
1 parent 22afd6b commit 53b9d2e

16 files changed

+393
-88
lines changed

PSScriptTools.psd1

130 Bytes
Binary file not shown.

PSScriptTools.psm1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Get-ChildItem -path $PSScriptRoot\functions\*.ps1 | ForEach-Object -process {
1111

1212
#add ToDo options to the ISE or VS Code
1313
if ($psEditor) {
14+
#This may not be working in newer versions of the PowerShell extension under PowerShell 7
1415
Write-Verbose "Defining VSCode additions"
1516
$sb = {
1617
Param(
@@ -23,8 +24,13 @@ if ($psEditor) {
2324
$todo = "# [$(Get-Date)] TODO: $item"
2425
$context.CurrentFile.InsertText($todo)
2526
}
26-
Register-EditorCommand -Name "Insert.ToDo" -DisplayName "Insert ToDo" -ScriptBlock $sb -SuppressOutput
27-
27+
$rParams = @{
28+
Name = "Insert.ToDo"
29+
DisplayName = "Insert ToDo"
30+
ScriptBlock = $sb
31+
SuppressOutput = $false
32+
}
33+
Register-EditorCommand @rParams
2834
}
2935
elseif ($psise) {
3036
Write-Verbose "Defining ISE additions"

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,14 @@ By default, the output will only show directory or equivalent structures. But yo
10711071

10721072
![show file system tree](images/show-tree1.png)
10731073

1074+
If you are running PowerShell 7 and specifying a file system path, you can display the tree in a colorized format by using the `-InColor` dynamic parameter.
1075+
1076+
![show file system tree](images/show-tree2.png)
1077+
1078+
I have long term plans to have a user-configurable color map for different item types.
1079+
1080+
This command has an alias of `pstree`.
1081+
10741082
## Format-Functions
10751083

10761084
A set of simple commands to make it easier to format values.
@@ -1276,8 +1284,22 @@ Mode LastWriteTime Length Name
12761284

12771285
You will need to manually install the file.
12781286

1287+
## Other
1288+
1289+
From time to time I will include additional items that you might find useful.
1290+
One item that you get when you import this module is a custom format.ps1xml file for services.
1291+
If you are running PowerShell 7, you can run `Get-Service` and pipe it to the table view.
1292+
1293+
```powershell
1294+
PS C:\> Get-Service | Format-Table -view ansi
1295+
```
1296+
1297+
This will display the service status color-coded.
1298+
1299+
![ServiceAnsi](images/serviceansi.png)
1300+
12791301
## Compatibility
12801302

12811303
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. It is assumed you will __not__ be running this commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
12821304

1283-
Last Updated *2020-02-27 16:34:43Z UTC*
1305+
Last Updated *2020-02-28 17:24:23Z UTC*

changelog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
# Change Log for PSScriptTools
22

3+
## v2.19.0
4+
5+
+ Modified `Get-FolderSizeInfo` to use [system.collections.arraylist]` to improve performance. (Issue #68)
6+
+ Fixed bug in `Get-FolderSizeInfo` running in PowerShell 7 that wasn't including System files.
7+
+ Updated help for `Get-FolderSizeInfo`
8+
+ Added online help link for `Get-PSScriptTools`.
9+
+ Added better error handling to `Test-EmptyFolder`
10+
+ Added `Computername` property to passthru output from `Test-EmptyFolder`
11+
+ Added alias `fcc` for `Find-CimClass`
12+
+ Added alias `pstree` for `Show-Tree`
13+
+ Revised `Show-Tree` to use splatting for internal commands
14+
+ Added a dynamic parameter `InColor` for `Show-Tree` to display results in ANSI color if running PowerShell 7.
15+
+ Added format file `serviceansi.format.ps1xml` to display service status colored when using PowerShell 7
16+
+ Updated `README.md`
17+
318
## v2.18.0
419

520
+ Fixed missing `ReleaseID` property in `Get-WindowsVersion` (Issue #67)

docs/Get-FolderSizeInfo.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Get-FolderSizeInfo [-Path] <String[]> [-Hidden] [<CommonParameters>]
2121

2222
This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all sub-folders.
2323

24+
Note that this command has been optimized for performance, but if you have a lot of files to count that will take time.
25+
2426
## EXAMPLES
2527

2628
### Example 1

docs/Get-PSScriptTools.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
external help file: PSScriptTools-help.xml
33
Module Name: PSScriptTools
4-
online version:
4+
online version: http://bit.ly/3acixBH
55
schema: 2.0.0
66
---
77

docs/Show-Tree.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Shows the specified path as a graphical tree in the console. This is intended as
3333

3434
By default, the output will only show directory or equivalent structures. But you can opt to include items well as item details.
3535

36-
It should work cross-platform.
36+
It should work cross-platform. If you are running PowerShell 7, there is a dynamic parameter, -InColor, that will write ANSI-colored output to the pipeline. The color scheme is designed for the file system.
3737

3838
Note: This is an update to an older function in my library. I seem to recall I found the original code somewhere online, perhaps from someone like Lee Holmes. Sadly, I neglected to record the source.
3939

@@ -107,7 +107,7 @@ Shows the hierarchy of registry keys and values (-ShowProperty), recursing down
107107
### EXAMPLE 3
108108

109109
```powershell
110-
PS C:\> Show-Tree.ps1 WSMan: -ShowItem
110+
PS C:\> Show-Tree WSMan: -ShowItem
111111
112112
WSMan:\
113113
\--localhost
@@ -240,8 +240,7 @@ Accept wildcard characters: False
240240
241241
### CommonParameters
242242
243-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
244-
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
243+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
245244
246245
## INPUTS
247246

docs/Test-EmptyFolder.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,17 @@ Test a single folder from a parameter.
3939
### Example 2
4040

4141
```powershell
42-
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru
43-
44-
Path Name IsEmpty
45-
---- ---- -------
46-
C:\work\A A False
47-
C:\work\alpha alpha False
48-
C:\work\B B False
49-
C:\work\data data False
50-
C:\work\demo3 demo3 True
42+
PS C:\> Get-ChildItem c:\work -Directory | test-EmptyFolder -passthru
43+
44+
45+
Path Name IsEmpty Computername
46+
---- ---- ------- ------------
47+
C:\work\A A False DESK10
48+
C:\work\alpha alpha False DESK10
49+
C:\work\B B True DESK10
50+
C:\work\data data False DESK10
51+
C:\work\demo3 demo3 True DESK10
52+
C:\work\demos demos False DESK10
5153
...
5254
```
5355

@@ -56,7 +58,7 @@ Test child folders under C:\work.
5658
### Example 3
5759

5860
```powershell
59-
PS C:\> Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
61+
PS C:\> Get-ChildItem c:\work -Directory | Test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
6062
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
6163
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
6264
What if: Performing the operation "Remove Directory" on target "C:\work\new".
@@ -73,7 +75,7 @@ The example is piping objects to ForEach-Object so that Remove-Item can use the
7375

7476
### -Passthru
7577

76-
Write a test object to the pipeline
78+
Write a test object to the pipeline.
7779

7880
```yaml
7981
Type: SwitchParameter

en-us/PSScriptTools-help.xml

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4148,6 +4148,7 @@ Mode LastWriteTime Length Name
41484148
</command:details>
41494149
<maml:description>
41504150
<maml:para>This command is an alternative to discovering the size of a folder, or at least an easier method. Use the -Hidden parameter to include hidden files in the output. The measurement will include all files in all sub-folders.</maml:para>
4151+
<maml:para>Note that this command has been optimized for performance, but if you have a lot of files to count that will take time.</maml:para>
41514152
</maml:description>
41524153
<command:syntax>
41534154
<command:syntaxItem>
@@ -5346,6 +5347,10 @@ ConvertTo-LocalTime clt Convert a foreign time to local
53465347
</command:example>
53475348
</command:examples>
53485349
<command:relatedLinks>
5350+
<maml:navigationLink>
5351+
<maml:linkText>Online Version:</maml:linkText>
5352+
<maml:uri>http://bit.ly/3acixBH</maml:uri>
5353+
</maml:navigationLink>
53495354
<maml:navigationLink>
53505355
<maml:linkText>Get-Command</maml:linkText>
53515356
<maml:uri></maml:uri>
@@ -10654,7 +10659,7 @@ Mode LastWriteTime Length Name
1065410659
<maml:description>
1065510660
<maml:para>Shows the specified path as a graphical tree in the console. This is intended as PowerShell alternative to the tree DOS command. This function should work for any type of PowerShell provider and can be used to explore providers used for configuration like the WSMan provider or the registry. Currently, this will not work with any PSDrives created with the Certificate provider.</maml:para>
1065610661
<maml:para>By default, the output will only show directory or equivalent structures. But you can opt to include items well as item details.</maml:para>
10657-
<maml:para>It should work cross-platform.</maml:para>
10662+
<maml:para>It should work cross-platform. If you are running PowerShell 7, there is a dynamic parameter, -InColor, that will write ANSI-colored output to the pipeline. The color scheme is designed for the file system.</maml:para>
1065810663
<maml:para>Note: This is an update to an older function in my library. I seem to recall I found the original code somewhere online, perhaps from someone like Lee Holmes. Sadly, I neglected to record the source.</maml:para>
1065910664
</maml:description>
1066010665
<command:syntax>
@@ -10946,7 +10951,7 @@ HKLM:\SOFTWARE\Microsoft\.NETFramework
1094610951
</command:example>
1094710952
<command:example>
1094810953
<maml:title>-------------------------- EXAMPLE 3 --------------------------</maml:title>
10949-
<dev:code>PS C:\&gt; Show-Tree.ps1 WSMan: -ShowItem
10954+
<dev:code>PS C:\&gt; Show-Tree WSMan: -ShowItem
1095010955

1095110956
WSMan:\
1095210957
\--localhost
@@ -11025,7 +11030,7 @@ WSMan:\
1102511030
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
1102611031
<maml:name>Passthru</maml:name>
1102711032
<maml:Description>
11028-
<maml:para>Write a test object to the pipeline</maml:para>
11033+
<maml:para>Write a test object to the pipeline.</maml:para>
1102911034
</maml:Description>
1103011035
<dev:type>
1103111036
<maml:name>SwitchParameter</maml:name>
@@ -11039,7 +11044,7 @@ WSMan:\
1103911044
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="named" aliases="none">
1104011045
<maml:name>Passthru</maml:name>
1104111046
<maml:Description>
11042-
<maml:para>Write a test object to the pipeline</maml:para>
11047+
<maml:para>Write a test object to the pipeline.</maml:para>
1104311048
</maml:Description>
1104411049
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
1104511050
<dev:type>
@@ -11105,23 +11110,25 @@ False</dev:code>
1110511110
</command:example>
1110611111
<command:example>
1110711112
<maml:title>-------------------------- Example 2 --------------------------</maml:title>
11108-
<dev:code>PS C:\&gt; Get-Childitem c:\work -Directory | test-EmptyFolder -passthru
11109-
11110-
Path Name IsEmpty
11111-
---- ---- -------
11112-
C:\work\A A False
11113-
C:\work\alpha alpha False
11114-
C:\work\B B False
11115-
C:\work\data data False
11116-
C:\work\demo3 demo3 True
11113+
<dev:code>PS C:\&gt; Get-ChildItem c:\work -Directory | test-EmptyFolder -passthru
11114+
11115+
11116+
Path Name IsEmpty Computername
11117+
---- ---- ------- ------------
11118+
C:\work\A A False DESK10
11119+
C:\work\alpha alpha False DESK10
11120+
C:\work\B B True DESK10
11121+
C:\work\data data False DESK10
11122+
C:\work\demo3 demo3 True DESK10
11123+
C:\work\demos demos False DESK10
1111711124
...</dev:code>
1111811125
<dev:remarks>
1111911126
<maml:para>Test child folders under C:\work.</maml:para>
1112011127
</dev:remarks>
1112111128
</command:example>
1112211129
<command:example>
1112311130
<maml:title>-------------------------- Example 3 --------------------------</maml:title>
11124-
<dev:code>PS C:\&gt; Get-Childitem c:\work -Directory | test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
11131+
<dev:code>PS C:\&gt; Get-ChildItem c:\work -Directory | Test-EmptyFolder -passthru | Where-object {$_.Isempty} | Foreach-Object { Remove-Item -LiteralPath $_.path -Recurse -force -whatif}
1112511132
What if: Performing the operation "Remove Directory" on target "C:\work\demo3".
1112611133
What if: Performing the operation "Remove Directory" on target "C:\work\installers".
1112711134
What if: Performing the operation "Remove Directory" on target "C:\work\new".

formats/serviceansi.format.ps1xml

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
format type data generated 02/03/2020 14:51:45 by BOVINE320\Jeff
4+
-->
5+
<Configuration>
6+
<ViewDefinitions>
7+
<View>
8+
<!--Created 02/03/2020 14:51:45 by BOVINE320\Jeff-->
9+
<Name>service</Name>
10+
<ViewSelectedBy>
11+
<TypeName>System.Service.ServiceController#StartupType</TypeName>
12+
</ViewSelectedBy>
13+
<TableControl>
14+
<!--Delete the AutoSize node if you want to use the defined widths.-->
15+
<TableHeaders>
16+
<TableColumnHeader>
17+
<Label>Status</Label>
18+
<Width>8</Width>
19+
<Alignment>left</Alignment>
20+
</TableColumnHeader>
21+
<TableColumnHeader>
22+
<Label>Name</Label>
23+
<Width>18</Width>
24+
<Alignment>left</Alignment>
25+
</TableColumnHeader>
26+
<TableColumnHeader>
27+
<Label>DisplayName</Label>
28+
<Width>42</Width>
29+
<Alignment>left</Alignment>
30+
</TableColumnHeader>
31+
</TableHeaders>
32+
<TableRowEntries>
33+
<TableRowEntry>
34+
<TableColumnItems>
35+
<TableColumnItem>
36+
<PropertyName>Status</PropertyName>
37+
</TableColumnItem>
38+
<TableColumnItem>
39+
<PropertyName>Name</PropertyName>
40+
</TableColumnItem>
41+
<TableColumnItem>
42+
<PropertyName>DisplayName</PropertyName>
43+
</TableColumnItem>
44+
</TableColumnItems>
45+
</TableRowEntry>
46+
</TableRowEntries>
47+
</TableControl>
48+
</View>
49+
<View>
50+
<!--Created 02/03/2020 14:51:45 by BOVINE320\Jeff-->
51+
<Name>Ansi</Name>
52+
<ViewSelectedBy>
53+
<TypeName>System.Service.ServiceController#StartupType</TypeName>
54+
</ViewSelectedBy>
55+
<TableControl>
56+
<!--Delete the AutoSize node if you want to use the defined widths.-->
57+
<TableHeaders>
58+
<TableColumnHeader>
59+
<Label>Status</Label>
60+
<Width>8</Width>
61+
<Alignment>left</Alignment>
62+
</TableColumnHeader>
63+
<TableColumnHeader>
64+
<Label>Name</Label>
65+
<Width>18</Width>
66+
<Alignment>left</Alignment>
67+
</TableColumnHeader>
68+
<TableColumnHeader>
69+
<Label>DisplayName</Label>
70+
<Width>42</Width>
71+
<Alignment>left</Alignment>
72+
</TableColumnHeader>
73+
</TableHeaders>
74+
<TableRowEntries>
75+
<TableRowEntry>
76+
<TableColumnItems>
77+
<TableColumnItem>
78+
<ScriptBlock>
79+
If ($_.status -eq "stopped") {
80+
"`e[38;2;197;15;31m$($_.status)`e[0m"
81+
}
82+
elseif ($_.status -eq "running") {
83+
"`e[38;2;19;161;14m$($_.status)`e[0m"
84+
}
85+
elseif ($_.status -eq "paused") {
86+
"`e[38;2;252;127;0m$($_.status)`e[0m"
87+
}
88+
else {
89+
$_.status
90+
}
91+
</ScriptBlock>
92+
</TableColumnItem>
93+
<TableColumnItem>
94+
<PropertyName>Name</PropertyName>
95+
</TableColumnItem>
96+
<TableColumnItem>
97+
<PropertyName>DisplayName</PropertyName>
98+
</TableColumnItem>
99+
</TableColumnItems>
100+
</TableRowEntry>
101+
</TableRowEntries>
102+
</TableControl>
103+
</View>
104+
</ViewDefinitions>
105+
</Configuration>

0 commit comments

Comments
 (0)