Skip to content

Commit 95a1909

Browse files
2.36.0
1 parent cc8b39a commit 95a1909

27 files changed

+818
-154
lines changed

PSScriptTools.psd1

326 Bytes
Binary file not shown.

PSScriptTools.psm1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ if ($myinvocation.line -match "-verbose") {
44
}
55
Write-Verbose "Loading public functions"
66

7-
Get-ChildItem -path $PSScriptRoot\functions\*.ps1 | ForEach-Object -process {
7+
#exclude Get-MyCounter.ps1 because it requires a Windows platform
8+
Get-ChildItem -path $PSScriptRoot\functions\*.ps1 -Exclude 'Get-MyCounter.ps1' | ForEach-Object -process {
89
Write-Verbose $_.fullname
910
. $_.FullName
1011
}
1112

13+
if ($IsWindows -OR ($PSEdition -eq 'Desktop')) {
14+
. "$PSScriptRoot\functions\Get-MyCounter.ps1"
15+
}
16+
1217
Write-Verbose "Define the global PSAnsiFileMap variable"
1318
$json = "psansifilemap.json"
1419

PSScriptToolsManual.pdf

421 KB
Binary file not shown.

README.md

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,11 @@ PS C:\> Get-WindowsVersion | Select-Object *
390390
391391
ProductName : Windows 10 Pro
392392
EditionID : Professional
393-
ReleaseID : 1909
394-
Build : 18363.657
395-
Branch : 19h1_release
396-
InstalledUTC : 7/5/2019 10:54:49 PM
397-
Computername : BOVINE320
393+
ReleaseID : 2009
394+
Build : 19042.906
395+
Branch : vb_release
396+
InstalledUTC : 10/16/2020 3:09:01 PM
397+
Computername : PROSPERO
398398
```
399399

400400
#### [Get-WindowsVersionString](docs/Get-WindowsVersionString.md)
@@ -403,8 +403,7 @@ This command is a variation of `Get-WindowsVersion` that returns a formatted str
403403

404404
```dos
405405
PS C:\> Get-WindowsVersionString
406-
BOVINE320 Windows 10 Pro Version Professional (OS Build 18363.657)
407-
406+
PROSPERO Windows 10 Pro Version Professional (OS Build 19042.906)
408407
```
409408

410409
### [New-PSDriveHere](docs/New-PSDriveHere.md)
@@ -1348,6 +1347,16 @@ These functions were first described at [https://jdhitsolutions.com/blog/powersh
13481347

13491348
## Console Utilities
13501349

1350+
### [Get-PSSessionInfo](docs/Get-PSSessionInfo.md)
1351+
1352+
`Get-PSSessionInfo` will display a summary of your current PowerShell session. It should work on all platforms.
1353+
1354+
![windows session](images/pssessioninfo-windows.png)
1355+
1356+
![linux session](images/pssessioninfo-linux.png)
1357+
1358+
If you are running in a PowerShell console session, and the Elevated value is True, it will be displayed in color. The Memory and Runtime values are calculated ScriptProperties.
1359+
13511360
### [ConvertTo-ASCIIArt](docs/ConvertTo-ASCIIArt.md)
13521361

13531362
`ConvertTo-ASCIIArt` can be used to transform a string of text into ASCII art. It utilizes the web service at https://artii.herokuapp.com which allows you to transform text. You might use this to create headers for your scripts or PowerShell profile.
@@ -1617,6 +1626,17 @@ TotalMemGB FreeMemGB PctFree
16171626

16181627
## Scripting Tools
16191628

1629+
### [Test-IsElevated](docs/Test-IsElevated.md)
1630+
1631+
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.
1632+
1633+
```dos
1634+
PS C:\> Test-IsElevated
1635+
False
1636+
```
1637+
1638+
You can also use the `Get-PSWho` command to get more information.
1639+
16201640
### [New-FunctionItem](docs/New-FunctionItem.md)
16211641

16221642
```powershell
@@ -2202,8 +2222,13 @@ che Copy-HelpExample
22022222
...
22032223
```
22042224

2205-
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)
2225+
Some custom formats use ANSI to highlight information, assuming you are running in PowerShell Console Host.
22062226

2227+
![alias options](images/get-alias-option.png)
2228+
2229+
In this format view, ReadOnly aliases are displayed in Red.
2230+
2231+
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)
22072232

22082233
### PSSpecialChar
22092234

@@ -2251,6 +2276,4 @@ If you find this module useful, you might also want to look at my PowerShell too
22512276

22522277
## Compatibility
22532278

2254-
Where possible, module commands have been tested with PowerShell 7, but not on 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 these commands on any edition of PowerShell Core or any beta releases of PowerShell 7.
2255-
2256-
Last Updated *2021-03-25 14:54:50Z*
2279+
Where possible, module commands have been tested with PowerShell 7, but not on 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 these commands on any edition of PowerShell Core, i.e PowerShell 6.x.

changelog.md

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

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

5+
## v2.36.0
6+
7+
+ Update `Get-MyVariable` to make it more compatible with PowerShell 7 ([Issue #103](https://github.com/jdhitsolutions/PSScriptTools/issues/103)). This also makes the command now compatible with the PowerShell ISE.
8+
+ Added table view called `Simple` to format file for Aliases.
9+
+ Modified `Options` table view in `alias.format.ps1xml` to highlight read-only aliases in Red using ANSI if running in a PowerShell console host.
10+
+ Updated `Get-PSLocation` to include `$PSHome`.
11+
+ Modified module to only dot source `Get-MyCounter.ps1` if running Windows. The file contains a class definition that uses a Windows-only reference and PowerShell "scans" the file before it dot sources it, which throws an exception on non-Windows platforms.
12+
+ Added command `Get-PSSessionInfo` and an alias of `gsin`. The command uses a new format file, `pssessioninfo.format.ps1xml`.
13+
+ Added command `Test-IsElevated`.
14+
+ Updated `Get-PSWho` to included elevated information for non-Windows platforms.
15+
+ Added format file `pswho.format.ps1xml`.
16+
+ Help updates
17+
+ Updated `README.md`.
18+
519
## v2.35.0
620

721
+ Added `ConvertTo-TitleCase` command with aliases of `totc` and `title`.

docs/Find-CimClass.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Find-CimClass [-Classname] <String> [-Exclude <String>]
2020

2121
## DESCRIPTION
2222

23-
This function is designed to search an entire CIM repository for a class name. Sometimes, you can guess a CIM/WMI 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.
23+
This function is designed to search an entire CIM repository for a class name. Sometimes, you can guess a CIM/WMI class name but not know the full name or even the correct namespace. Find-CimClass will recursively search for a given classname in all namespaces. You can use wildcards and search remote computers.
2424

2525
This command requires a Windows platform.
2626

docs/Get-MyVariable.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Get-MyVariable [[-Scope] <String>] [-NoTypeInformation] [<CommonParameters>]
2121

2222
This function will return all variables not defined by PowerShell or by this function itself. The default is to return all user-created variables from the global scope but you can also specify a scope such as script, local, or a number 0 through 5. The command will also display the value type for each variable. If you want to suppress this output use the -NoTypeInformation switch.
2323

24-
This function is designed to work with the PowerShell console, NOT the PowerShell ISE.
2524

2625
## EXAMPLES
2726

docs/Get-PSLocation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Temp : C:\Users\Jeff\AppData\Local\Temp\
3232
Home : C:\Users\Jeff\Documents
3333
Desktop : C:\Users\Jeff\Desktop
3434
PowerShell : C:\Users\Jeff\Documents\WindowsPowerShell
35+
PSHome : C:\Windows\System32\WindowsPowerShell\v1.0
3536
```
3637

3738
Results on a Windows system.
@@ -45,6 +46,7 @@ Temp : /tmp/
4546
Home : /home/jeff
4647
Desktop :
4748
PowerShell : /home/jeff/.config/powershell
49+
PSHome : /opt/microsoft/powershell/7
4850
```
4951

5052
Results on a Linux system running PowerShell.
@@ -61,7 +63,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable
6163

6264
## OUTPUTS
6365

64-
### System.Object
66+
### PSLocation
6567

6668
## NOTES
6769

docs/Get-PSSessionInfo.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Get-PSSessionInfo
9+
10+
## SYNOPSIS
11+
12+
Get details about the current PowerShell session
13+
14+
## SYNTAX
15+
16+
```yaml
17+
Get-PSSessionInfo [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
This command will provide a snapshot of the current PowerShell session. The Runtime and Memory properties are defined by script so if you save the result to a variable, you will get current values everytime you look at the variable.
23+
24+
## EXAMPLES
25+
26+
### Example 1
27+
28+
```powershell
29+
PS C:\> Get-PSSessionInfo
30+
31+
ProcessID : 1112
32+
Command : "C:\Program Files\PowerShell\7\pwsh.exe" -noprofile
33+
Host : ConsoleHost
34+
Started : 4/9/2021 9:36:13 AM
35+
PSVersion : 7.1.3
36+
Elevated : True
37+
Parent : System.Diagnostics.Process (WindowsTerminal)
38+
Runtime : 00:31:26.2716486
39+
MemoryMB : 129
40+
```
41+
42+
The Memory value is in MB. If running in a PowerShell console session, the Elevated value will be displayed in color.
43+
44+
### Example 2
45+
46+
```powershell
47+
PS /home> Get-PSSessionInfo
48+
49+
ProcessID : 71
50+
Command : pwsh
51+
Host : ConsoleHost
52+
Started : 04/09/2021 09:38:55
53+
PSVersion : 7.1.3
54+
Elevated : False
55+
Parent : System.Diagnostics.Process (bash)
56+
Runtime : 00:30:07.1669248
57+
MemoryMB : 133
58+
```
59+
60+
The result from a Linux host.
61+
62+
## PARAMETERS
63+
64+
### CommonParameters
65+
66+
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).
67+
68+
## INPUTS
69+
70+
### None
71+
72+
## OUTPUTS
73+
74+
### PSSessionInfo
75+
76+
## NOTES
77+
78+
This command has an alias of gsin.
79+
80+
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
81+
82+
## RELATED LINKS
83+
84+
[Get-Host]()
85+
86+
[Get-Process]()

docs/Get-PSWho.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ The default behavior is to write an object to the pipeline, but you can use the
3030
```powershell
3131
PS C:\> Get-PSWho
3232
33-
User : WIN10\Jeff
34-
Elevated : True
35-
Computername : WIN10
33+
User : Desk01\Jeff
34+
Elevated : False
35+
Computername : Desk01
3636
OperatingSystem : Microsoft Windows 10 Pro [64-bit]
37-
OSVersion : 10.0.18363
38-
PSVersion : 5.1.18362.145
37+
OSVersion : 10.0.19042
38+
PSVersion : 5.1.19041.906
3939
Edition : Desktop
4040
PSHost : ConsoleHost
4141
WSMan : 3.0
@@ -49,11 +49,11 @@ Culture : English (United States)
4949
PS /home/jhicks> Get-PSWho
5050
5151
User : jeff
52-
Elevated : NA
53-
Computername : WIN10
54-
OperatingSystem : Linux 4.4.0-18362-Microsoft #476-Microsoft Fri Nov 01 16:53:00 PST 2019
55-
OSVersion : Ubuntu 18.04.3 LTS
56-
PSVersion : 7.0.0-rc.2
52+
Elevated : False
53+
Computername : Desk01
54+
OperatingSystem : Linux 5.4.72-microsoft-standard-WSL2 #1 SMP Wed Oct 28 23:40:43 UTC 2020
55+
OSVersion : Ubuntu 20.04.2 LTS
56+
PSVersion : 7.1.3
5757
Edition : Core
5858
PSHost : ConsoleHost
5959
WSMan : 3.0
@@ -66,12 +66,12 @@ Culture : Invariant Language (Invariant Country)
6666
```powershell
6767
PS C:\> Get-PSWho
6868
69-
User : WIN10\Jeff
69+
User : Desk01\Jeff
7070
Elevated : True
71-
Computername : WIN10
71+
Computername : Desk01
7272
OperatingSystem : Microsoft Windows 10 Pro [64-bit]
7373
OSVersion : 10.0.19042
74-
PSVersion : 7.1.0
74+
PSVersion : 7.1.3
7575
Edition : Core
7676
PSHost : ConsoleHost
7777
WSMan : 3.0
@@ -123,6 +123,8 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
123123
124124
## RELATED LINKS
125125
126+
[Test-IsElevated](Test-IsElevated.md)
127+
126128
[Get-CimInstance]()
127129
128130
[Get-ExecutionPolicy]()

docs/Test-IsElevated.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Test-IsElevated
9+
10+
## SYNOPSIS
11+
12+
Test if the current user is running elevated.
13+
14+
## SYNTAX
15+
16+
```yaml
17+
Test-IsElevated [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
This command will test if the current session is running elevated, or as Administrator. On Windows platforms, the command uses the NET Framework to determine if the user is running as Administrator. On non-Windows systems, the command is checking the user's UID value.
23+
24+
## EXAMPLES
25+
26+
### Example 1
27+
28+
```powershell
29+
PS C:\> Test-IsElevated
30+
True
31+
```
32+
33+
## PARAMETERS
34+
35+
### CommonParameters
36+
37+
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).
38+
39+
## INPUTS
40+
41+
### None
42+
43+
## OUTPUTS
44+
45+
### Boolean
46+
47+
## NOTES
48+
49+
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
50+
51+
## RELATED LINKS
52+
53+
[Get-PSWho](Get-PSWho.md)

0 commit comments

Comments
 (0)