Skip to content

Commit 6365005

Browse files
see changelog for v2.6.0
1 parent b30200b commit 6365005

11 files changed

Lines changed: 447 additions & 27 deletions

PSScriptTools.psd1

104 Bytes
Binary file not shown.

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,28 @@ Now Home Seattle New Zealand
792792

793793
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.
794794

795+
### [ConvertTo-LocalTime](docs/ConvertTo-LocalTime.md)
796+
797+
It can be tricky sometimes to see a time in a foreign location and try to figure out what that time is locally. This command attempts to simplify this process. In addition to the remote time, you need the base UTC offset for the remote location.
798+
799+
```powershell
800+
PS C:\> get-timezone -ListAvailable | where id -match hawaii
801+
802+
803+
Id : Hawaiian Standard Time
804+
DisplayName : (UTC-10:00) Hawaii
805+
StandardName : Hawaiian Standard Time
806+
DaylightName : Hawaiian Daylight Time
807+
BaseUtcOffset : -10:00:00
808+
SupportsDaylightSavingTime : False
809+
810+
PS C:\> Convertto-LocalTime "10:00AM" -10:00:00
811+
812+
Thursday, March 14, 2019 4:00:00 PM
813+
```
814+
815+
In this example, the user if first determining the UTC offset for Hawaii. Then 10:00AM in say Honolulu, is converted to local time which in this example is in the Eastern Time zone.
816+
795817
## Console Utilities
796818

797819
### [Set-ConsoleTitle](docs/Set-ConsoleTitle.md)
@@ -818,4 +840,4 @@ PS C:\> Set-ConsoleColor -background DarkGray -foreground Yellow
818840

819841
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.
820842

821-
*last updated 11 March, 2019*
843+
*last updated 14 March, 2019*

changelog.md

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

3+
## v2.6.0
4+
5+
+ Modified `Convertto-WPFGrid` to set maximum size equal to total available working area (Issue #36)
6+
+ Modified `Convertto-WPFGrid` to change cursor on refresh and display a refresh message in the title bar
7+
+ Added InitializationScript option for `ConvertTo-WPFGrid` (Issue #42)
8+
+ Added `ConvertTo-LocalTime` with an alias of `clt`
9+
+ Help updates
10+
311
## v2.5.0
412

513
+ fixed bug which was hiding the horizontal scroll bar in `ConvertTo-WPFGrid` (Issue #40)
614
+ fixed bug which prevented status bar from updating when manually refreshing in `ConvertTo-WPFGrid` (Issue #34)
7-
+ Changed time display in `ConvertTo-WPFGrid as a timespan instead of raw seconds (Issue #41)
15+
+ Changed time display in `ConvertTo-WPFGrid` as a timespan instead of raw seconds (Issue #41)
816
+ Markdown help cleanup
917
+ Added `Set-ConsoleTitle`
1018
+ Added `Set-ConsoleColor`

docs/Convert-CommandtoHashtable.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,5 @@ For more information, see about_CommonParameters (http://go.microsoft.com/fwlink
7373
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
7474
7575
## RELATED LINKS
76+
77+
[Convert-HashTableToCode]()

docs/ConvertTo-UTCTime.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ For more information, see about_CommonParameters (http://go.microsoft.com/fwlink
7171
7272
## NOTES
7373
74-
Learn more about PowerShell:
75-
http://jdhitsolutions.com/blog/essential-powershell-resources/
74+
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
7675
7776
## RELATED LINKS
7877

docs/ConvertTo-WPFGrid.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ Send command output to an interactive WPF-based grid.
1616
### input (Default)
1717

1818
```yaml
19-
ConvertTo-WPFGrid [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseLocalVariable <String[]>]
20-
[-UseProfile] [<CommonParameters>]
19+
ConvertTo-WPFGrid [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-InitializationScript <ScriptBlock>]
20+
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
2121
```
2222

2323
### Input
2424

2525
```yaml
2626
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
27-
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
27+
[-InitializationScript <ScriptBlock>] [-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
2828
```
2929

3030
### scriptblock
3131

3232
```yaml
3333
ConvertTo-WPFGrid [-Scriptblock <ScriptBlock>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
34-
[-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
34+
[-InitializationScript <ScriptBlock>] [-UseLocalVariable <String[]>] [-UseProfile] [<CommonParameters>]
3535
```
3636

3737
## DESCRIPTION
3838

3939
This command is an alternative to Out-Gridview. It works much the same way. Run a PowerShell command and pipe it to this command. The output will be displayed in an auto-sized data grid. You can click on column headings to sort. You can resize columns and you can re-order columns. You will want to be selective about which properties you pipe through to this command. See examples.
4040

41-
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. Beginning with v2.4.0 the form now has a Refresh button which will automatically refresh the datagrid.
41+
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. Beginning with v2.4.0 the form now has a Refresh button which will automatically refresh the datagrid. You should set a refresh interval that is greater than the time it takes to complete the command.
4242

43-
Because the grid is running in a new background runspace, it does not automatically inherit anything from your current session. However, you can use the -UserProfile parameter which will load your user profile scripts into the runspace. You can also specify a list of locally defined variables to be used in the form.
43+
Because the grid is running in a new background runspace, it does not automatically inherit anything from your current session. However, you can use the -UserProfile parameter which will load your user profile scripts into the runspace. You can specify a list of locally defined variables to be used in the form. Use the variable name without the $. Finally, you can also use the -InitializationScript parameter and specify a scriptblock of PowerShell code to initialize the runspace. This is helpful when you need to dot source external scripts or import modules not in your module path.
4444

4545
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.
4646

@@ -74,6 +74,14 @@ PS C:\> Get-VMData -host CHI-HVR2 | ConvertTo-WPFGrid -title "VM Data" -refresh
7474

7575
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.
7676

77+
### EXAMPLE 4
78+
79+
```powershell
80+
PS C:\> (get-processdata -Computername $computers).where({$_.workingset -ge 100mb}) | ConvertTo-WPFGrid -Title "Process Report" -UseLocalVariable computers -InitializationScript {. C:\scripts\Get-ProcessData.ps1} -Refresh -Timeout 30
81+
```
82+
83+
This command runs a function that is defined in a script file. In order for the form to refresh, it must also dot source the script which is happening with the InitializationScript parameter. The example is also loading the local $computers variable so that it too is available upon refresh.
84+
7785
## PARAMETERS
7886

7987
### -InputObject
@@ -126,7 +134,9 @@ Accept wildcard characters: False
126134
127135
### -Refresh
128136
129-
If you specify this parameter and a Timeout value, this command will refresh the datagrid with the PowerShell expression piped into ConvertTo-WPFGrid. This will only work if you are using this command at the end of a pipelined expression. See examples.
137+
If you specify this parameter and a Timeout value, this command will refresh the datagrid with the PowerShell expression piped into ConvertTo-WPFGrid. You should use a value that is longer than the time it takes to complete the command that generates your data.
138+
139+
This parameter will only work if you are using Convertto-WPFGrid at the end of a pipelined expression. See examples.
130140
131141
```yaml
132142
Type: SwitchParameter
@@ -188,6 +198,22 @@ Accept pipeline input: False
188198
Accept wildcard characters: False
189199
```
190200
201+
### -InitializationScript
202+
203+
Run this scriptblock to initialize the background runspace. You might need to dot source a script file or load a non-standard module.
204+
205+
```yaml
206+
Type: ScriptBlock
207+
Parameter Sets: (All)
208+
Aliases:
209+
210+
Required: False
211+
Position: Named
212+
Default value: None
213+
Accept pipeline input: False
214+
Accept wildcard characters: False
215+
```
216+
191217
### CommonParameters
192218
193219
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).
@@ -210,4 +236,4 @@ Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell
210236
211237
[ConvertTo-HTML]()
212238
213-
[ConvertTo-Markdown](./ConvertTo-Markdown.md)
239+
[ConvertTo-Markdown](./ConvertTo-Markdown.md)

docs/Convertto-LocalTime.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
---
2+
external help file: PSScriptTools-help.xml
3+
Module Name: PSScriptTools
4+
online version:
5+
schema: 2.0.0
6+
---
7+
8+
# Convertto-LocalTime
9+
10+
## SYNOPSIS
11+
12+
Convert a foreign time to local
13+
14+
## SYNTAX
15+
16+
```yaml
17+
Convertto-LocalTime [-Datetime] <DateTime> [-UTCOffset] <TimeSpan> [<CommonParameters>]
18+
```
19+
20+
## DESCRIPTION
21+
22+
It can be tricky sometimes to see a time in a foreign location and try to figure out what that time is locally. This command attempts to simplify this process. In addition to the remote time, you need the base UTC offset for the remote location. You can use Get-Timezone to help. See examples.
23+
24+
## EXAMPLES
25+
26+
### Example 1
27+
28+
```powershell
29+
PS C:\> ConvertTo-LocalTime "3/15/2019 7:00AM" 8:00:00
30+
31+
Thursday, March 14, 2019 7:00:00 PM
32+
```
33+
34+
Convert a time that is in Singapore to local (Eastern) time.
35+
36+
### Example 2
37+
38+
```powershell
39+
PS C:\> get-timezone -ListAvailable | where id -match hawaii
40+
41+
42+
Id : Hawaiian Standard Time
43+
DisplayName : (UTC-10:00) Hawaii
44+
StandardName : Hawaiian Standard Time
45+
DaylightName : Hawaiian Daylight Time
46+
BaseUtcOffset : -10:00:00
47+
SupportsDaylightSavingTime : False
48+
49+
PS C:\> ConvertTo-LocalTime "10:00AM" -10:00:00
50+
51+
Thursday, March 14, 2019 4:00:00 PM
52+
```
53+
54+
In this example, the user if first determining the UTC offset for Hawaii. Then 10:00AM in say Honolulu, is converted to local time which in this example is in the Eastern Time zone.
55+
56+
## PARAMETERS
57+
58+
### -Datetime
59+
60+
Enter a non-local date time
61+
62+
```yaml
63+
Type: DateTime
64+
Parameter Sets: (All)
65+
Aliases:
66+
67+
Required: True
68+
Position: 0
69+
Default value: None
70+
Accept pipeline input: False
71+
Accept wildcard characters: False
72+
```
73+
74+
### -UTCOffset
75+
76+
Enter the location's' UTC Offset. You can use Get-Timezone to discover it.
77+
78+
```yaml
79+
Type: TimeSpan
80+
Parameter Sets: (All)
81+
Aliases:
82+
83+
Required: True
84+
Position: 1
85+
Default value: None
86+
Accept pipeline input: False
87+
Accept wildcard characters: False
88+
```
89+
90+
### CommonParameters
91+
92+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
93+
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
94+
95+
## INPUTS
96+
97+
### None
98+
99+
## OUTPUTS
100+
101+
### DateTime
102+
103+
## NOTES
104+
105+
Learn more about PowerShell: http://jdhitsolutions.com/blog/essential-powershell-resources/
106+
107+
## RELATED LINKS
108+
109+
[Get-TimeZone]()
110+
111+
[Get-MyTimeInfo]()
112+
113+
[ConvertFrom-UTCTime]()
114+
115+
[ConvertTo-UTCTime]()

docs/PSScriptTools.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,14 @@ Convert a universal time to local time.
183183

184184
Display a time settings for a collection of locations.
185185

186-
### [Set-ConsoleTitle](./Set-ConsoleTitle)
186+
### [Set-ConsoleTitle](./Set-ConsoleTitle.md)
187187

188188
Set the title bar of the current PowerShell console window.
189189

190-
### [Set-ConsoleColor](./Set-ConsoleColor)
190+
### [Set-ConsoleColor](./Set-ConsoleColor.md)
191191

192-
Configure the foreground or background color of the current PowerShell console window.
192+
Configure the foreground or background color of the current PowerShell console window.
193+
194+
### [ConvertTo-LocalTime](./ConvertTo-LocalTime.md)
195+
196+
Convert a non-local datetime to your local time.

0 commit comments

Comments
 (0)