Skip to content

Commit cede9f6

Browse files
see changelong for v2.3.0
1 parent 1ce78c2 commit cede9f6

13 files changed

+1341
-138
lines changed

PSScriptTools.psd1

320 Bytes
Binary file not shown.

README.md

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# ![toolbox](./images/toolbox-thumbnail.png) PSScriptTools
1+
# PSScriptTools
2+
3+
[![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/)
24

35
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.
46

@@ -691,8 +693,60 @@ IsDynamic : False
691693
ParameterSet : __AllParameterSets
692694
```
693695

696+
## Time Functions
697+
698+
The module has a few date and time related commands.
699+
700+
### [ConvertTo-UTCTime](docs/ConvertTo-UTCTime.md)
701+
702+
Convert a local datetime value to universal time. The default is to convert now but you can specify a datetime value.
703+
704+
```powershell
705+
PS C:\> ConvertTo-UTCTime
706+
707+
Monday, March 4, 2019 5:51:26 PM
708+
```
709+
710+
Convert a datetime that is UTC-5 to universal time.
711+
712+
### [ConvertFrom-UTCTime](docs/ConvertFrom-UTCTime.md)
713+
714+
```powershell
715+
PS C:\> ConvertFrom-UTCTime "3/4/2019 6:00PM"
716+
717+
Monday, March 4, 2019 1:00:00 PM
718+
```
719+
720+
Convert a universal datetime to the local time.
721+
722+
### [Get-MyTimeInfo](./Get-MyTimeInfo.md)
723+
724+
Display a time settings for a collection of locations. This command is a PowerShell equivalent of a world clock. It will display a datetime value against a collection of locations. You can specify an ordered hashtable of locations and time zones. You can run command like:
725+
726+
```powershell
727+
[System.TimeZoneinfo]::GetSystemTimeZones() | out-gridview
728+
```
729+
730+
or
731+
732+
```powershell
733+
Get-TimeZone -listavailable
734+
```
735+
736+
To discover time zone names. Note that the ID is case-sensitive. You can then use the command like this:
737+
738+
```powershell
739+
PS C:\> Get-MyTimeInfo -Locations ([ordered]@{Seattle="Pacific Standard time";"New Zealand" = "New Zealand Standard Time"}) -HomeTimeZone "central standard time" | Select Now,Home,Seattle,'New Zealand'
740+
741+
Now Home Seattle New Zealand
742+
--- ---- ------- -----------
743+
3/4/2019 1:18:36 PM 3/4/2019 12:18:36 PM 3/4/2019 10:18:36 AM 3/5/2019 7:18:36 AM
744+
```
745+
746+
This is a handy command when traveling and your laptop is using a locally derived time and you want to see the time in other locations. It is recommended that you set a PSDefaultParameter value for the HomeTimeZone parameter in your PowerShell profile.
747+
694748
## Compatibility
695749

696750
Where possible these commands have been tested with PowerShell Core, but not every platform. If you encounter problems, have suggestions or other feedback, please post an issue.
697751

698-
*last updated 21 February 2019*
752+
*last updated 4 March 2019*

changelog.md

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

3+
## v2.3.0
4+
5+
+ Fixed bug in `ConvertTo-WPFGrid` that wasn't updating last update time. (Issue #30)
6+
+ Modified `ConvertTo-WPFGrid` to allow user to load their profile scripts into the runspace. (Issue #29)
7+
+ Modified auto sizing code in `ConvertTo-WPFGrid`
8+
+ Modified `ConvertTo-WPFGrid` to automatically display scroll bars when necessary.
9+
+ Modified `New-PSFormatXML` to display a warning on invalid property names. (Issue #33)
10+
+ Added `Get-myTimeInfo`, `ConvertTo-UTCTime` and `ConvertFrom-UTCTime` (Issue #31)
11+
+ help updates
12+
+ Updated `README.md`
13+
314
## v2.2.0
415

516
+ Code revisions in `ConvertTo-WPFGrid` (Issue #27)

docs/ConvertFrom-UTCTime.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertFrom-UTCTime
9+
10+
## SYNOPSIS
11+
12+
Convert a datetime value from universal
13+
14+
## SYNTAX
15+
16+
```yaml
17+
ConvertFrom-UTCTime [-DateTime] <DateTime> [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
Use this command to convert a universal datetime object into local time.
23+
24+
This command was introduced in v2.3.0.
25+
26+
## EXAMPLES
27+
28+
### Example 1
29+
30+
```powershell
31+
PS C:\> ConvertFrom-UTCTime "18:00"
32+
33+
Monday, March 4, 2019 1:00:00 PM
34+
```
35+
36+
Covert the time 18:00 for the current day from universal time to local time. This result reflects Eastern Time which on this date is UTC-5.
37+
38+
## PARAMETERS
39+
40+
### -DateTime
41+
42+
Enter a Universal Datetime value
43+
44+
```yaml
45+
Type: DateTime
46+
Parameter Sets: (All)
47+
Aliases:
48+
49+
Required: True
50+
Position: 0
51+
Default value: None
52+
Accept pipeline input: True (ByValue)
53+
Accept wildcard characters: False
54+
```
55+
56+
### CommonParameters
57+
58+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
59+
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
60+
61+
## INPUTS
62+
63+
### System.DateTime
64+
65+
## OUTPUTS
66+
67+
### System.DateTime
68+
69+
## NOTES
70+
71+
Learn more about PowerShell:
72+
http://jdhitsolutions.com/blog/essential-powershell-resources/
73+
74+
## RELATED LINKS
75+
76+
[ConvertTo-UTCTime]()

docs/ConvertTo-UTCTime.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# ConvertTo-UTCTime
9+
10+
## SYNOPSIS
11+
12+
Convert a local datetime to universal time.
13+
14+
## SYNTAX
15+
16+
```yaml
17+
ConvertTo-UTCTime [[-DateTime] <DateTime>] [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
Convert a local datetime to universal time. The default is now but you can specify a datetime value.
23+
24+
This command was introduced in v2.3.0.
25+
26+
## EXAMPLES
27+
28+
### Example 1
29+
30+
```powershell
31+
PS S:\PSScriptTools> get-date
32+
33+
Monday, March 4, 2019 12:51:47 PM
34+
35+
36+
PS S:\PSScriptTools> ConvertTo-UTCTime
37+
38+
Monday, March 4, 2019 5:51:49 PM
39+
```
40+
41+
## PARAMETERS
42+
43+
### -DateTime
44+
+
45+
Enter a Datetime value
46+
47+
```yaml
48+
Type: DateTime
49+
Parameter Sets: (All)
50+
Aliases:
51+
52+
Required: False
53+
Position: 0
54+
Default value: now
55+
Accept pipeline input: True (ByValue)
56+
Accept wildcard characters: False
57+
```
58+
59+
### CommonParameters
60+
61+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
62+
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
63+
64+
## INPUTS
65+
66+
### System.DateTime
67+
68+
## OUTPUTS
69+
70+
### System.DateTime
71+
72+
## NOTES
73+
74+
Learn more about PowerShell:
75+
http://jdhitsolutions.com/blog/essential-powershell-resources/
76+
77+
## RELATED LINKS
78+
79+
[ConvertFrom-UTCTime]()

docs/ConvertTo-WPFGrid.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Send command output to an interactive WPF-based grid.
1414
## SYNTAX
1515

1616
```yaml
17-
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
17+
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseProfile]
1818
[<CommonParameters>]
1919
```
2020

@@ -24,14 +24,16 @@ This command is an alternative to Out-Gridview. It works much the same way. Run
2424

2525
You can specify a timeout value which will automatically close the form. If you specify a timeout and the Refresh parameter, then the contents of the datagrid will automatically refreshed using the timeout value as an integer. This will only work when you pipe a PowerShell expression to ConvertTo-WPFGrid as one command. This will fail if you break the command in the PowerShell ISE or use a nested prompt.
2626

27+
Because the grid is running in a new background runspace, it does not automatically inherit anything from your current session. When refreshing data, you need to make sure that the command up to ConvertTo-WPFGrid can run in a standalone session. For example, avoid using variables that won't exist in the background runspace. However, you can use the -UserProfile parameter which will load your user profile scripts into the runspace.
28+
2729
This command runs the WPF grid in a new runspace so your PowerShell prompt will not be blocked. However, after closing the form you may be left with the runspace. You can use Remove-Runspace to clean up or wait until you restart PowerShell.
2830

2931
## EXAMPLES
3032

3133
### EXAMPLE 1
3234

3335
```powershell
34-
PS C:\> get-process | sort-object WS -Descending | Select -first 20 ID,Name,WS,VM,PM,Handles,StartTime | Convertto-WPFGrid -Refresh -timeout 20 -Title "Top Processes"
36+
PS C:\> get-process | sort-object WS -Descending | Select-object -first 20 ID,Name,WS,VM,PM,Handles,StartTime | Convertto-WPFGrid -Refresh -timeout 20 -Title "Top Processes"
3537
```
3638

3739
Get the top 20 processes based on the value of the WorkingSet property and display selected properties in the WPF Grid. The contents will automatically refresh every 20 seconds. You will need to manually close the form.
@@ -41,13 +43,21 @@ Get the top 20 processes based on the value of the WorkingSet property and displ
4143
```powershell
4244
PS C:\> $vmhost = "CHI-HVR2"
4345
PS C:\> Get-VM -computername $VMHost | Select Name,State,Uptime,
44-
@{Name="AssignedMB";Expression={$_.MemoryAssigned/1mb -as \[int\]}},
45-
@{Name="DemandMB";Expression={$_.MemoryDemand/1mb -as \[int\]}} |
46+
@{Name="AssignedMB";Expression={$_.MemoryAssigned/1mb -as [int]}},
47+
@{Name="DemandMB";Expression={$_.MemoryDemand/1mb -as [int]}} |
4648
ConvertTo-WPFGrid -title "VM Report $VMHost" -timeout 20
4749
```
4850

4951
Get Hyper-V virtual machine information and display for 20 seconds before automatically closing. Note that this would be written as one long pipelined expression. It is formatted here for the sake of the help documentation.
5052

53+
### EXAMPLE 3
54+
55+
```powershell
56+
PS C:\> Get-VMData -host CHI-HVR2 | ConvertTo-WPFGrid -title "VM Data" -refresh -timeout 60 -useprofile
57+
```
58+
59+
This example uses a hypothetical command that might be defined in a PowerShell profile script. ConvertTo-WPFGrid will load the profile scripts so that the data can be updated every 60 seconds.
60+
5161
## PARAMETERS
5262

5363
### -InputObject
@@ -114,6 +124,22 @@ Accept pipeline input: False
114124
Accept wildcard characters: False
115125
```
116126
127+
### -UseProfile
128+
129+
Load your PowerShell profiles into the background runspace.
130+
131+
```yaml
132+
Type: SwitchParameter
133+
Parameter Sets: (All)
134+
Aliases:
135+
136+
Required: False
137+
Position: Named
138+
Default value: None
139+
Accept pipeline input: False
140+
Accept wildcard characters: False
141+
```
142+
117143
### CommonParameters
118144
119145
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).

0 commit comments

Comments
 (0)