Skip to content

Commit

Permalink
see changelong for v2.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jdhitsolutions committed Mar 4, 2019
1 parent 1ce78c2 commit cede9f6
Show file tree
Hide file tree
Showing 13 changed files with 1,341 additions and 138 deletions.
Binary file modified PSScriptTools.psd1
Binary file not shown.
58 changes: 56 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# ![toolbox](./images/toolbox-thumbnail.png) PSScriptTools
# PSScriptTools

[![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/)

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.

Expand Down Expand Up @@ -691,8 +693,60 @@ IsDynamic : False
ParameterSet : __AllParameterSets
```

## Time Functions

The module has a few date and time related commands.

### [ConvertTo-UTCTime](docs/ConvertTo-UTCTime.md)

Convert a local datetime value to universal time. The default is to convert now but you can specify a datetime value.

```powershell
PS C:\> ConvertTo-UTCTime
Monday, March 4, 2019 5:51:26 PM
```

Convert a datetime that is UTC-5 to universal time.

### [ConvertFrom-UTCTime](docs/ConvertFrom-UTCTime.md)

```powershell
PS C:\> ConvertFrom-UTCTime "3/4/2019 6:00PM"
Monday, March 4, 2019 1:00:00 PM
```

Convert a universal datetime to the local time.

### [Get-MyTimeInfo](./Get-MyTimeInfo.md)

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:

```powershell
[System.TimeZoneinfo]::GetSystemTimeZones() | out-gridview
```

or

```powershell
Get-TimeZone -listavailable
```

To discover time zone names. Note that the ID is case-sensitive. You can then use the command like this:

```powershell
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'
Now Home Seattle New Zealand
--- ---- ------- -----------
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
```

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.

## Compatibility

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.

*last updated 21 February 2019*
*last updated 4 March 2019*
11 changes: 11 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log for PSScriptTools

## v2.3.0

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

## v2.2.0

+ Code revisions in `ConvertTo-WPFGrid` (Issue #27)
Expand Down
76 changes: 76 additions & 0 deletions docs/ConvertFrom-UTCTime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
external help file: PSScriptTools-help.xml
Module Name: PSScriptTools
online version:
schema: 2.0.0
---

# ConvertFrom-UTCTime

## SYNOPSIS

Convert a datetime value from universal

## SYNTAX

```yaml
ConvertFrom-UTCTime [-DateTime] <DateTime> [<CommonParameters>]
```

## DESCRIPTION

Use this command to convert a universal datetime object into local time.

This command was introduced in v2.3.0.

## EXAMPLES

### Example 1

```powershell
PS C:\> ConvertFrom-UTCTime "18:00"
Monday, March 4, 2019 1:00:00 PM
```

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.

## PARAMETERS

### -DateTime

Enter a Universal Datetime value

```yaml
Type: DateTime
Parameter Sets: (All)
Aliases:

Required: True
Position: 0
Default value: None
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### CommonParameters
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).
## INPUTS
### System.DateTime
## OUTPUTS
### System.DateTime
## NOTES
Learn more about PowerShell:
http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[ConvertTo-UTCTime]()
79 changes: 79 additions & 0 deletions docs/ConvertTo-UTCTime.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
external help file: PSScriptTools-help.xml
Module Name: PSScriptTools
online version:
schema: 2.0.0
---

# ConvertTo-UTCTime

## SYNOPSIS

Convert a local datetime to universal time.

## SYNTAX

```yaml
ConvertTo-UTCTime [[-DateTime] <DateTime>] [<CommonParameters>]
```

## DESCRIPTION

Convert a local datetime to universal time. The default is now but you can specify a datetime value.

This command was introduced in v2.3.0.

## EXAMPLES

### Example 1

```powershell
PS S:\PSScriptTools> get-date
Monday, March 4, 2019 12:51:47 PM
PS S:\PSScriptTools> ConvertTo-UTCTime
Monday, March 4, 2019 5:51:49 PM
```

## PARAMETERS

### -DateTime
+
Enter a Datetime value

```yaml
Type: DateTime
Parameter Sets: (All)
Aliases:

Required: False
Position: 0
Default value: now
Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```
### CommonParameters
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).
## INPUTS
### System.DateTime
## OUTPUTS
### System.DateTime
## NOTES
Learn more about PowerShell:
http://jdhitsolutions.com/blog/essential-powershell-resources/
## RELATED LINKS
[ConvertFrom-UTCTime]()
34 changes: 30 additions & 4 deletions docs/ConvertTo-WPFGrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Send command output to an interactive WPF-based grid.
## SYNTAX

```yaml
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh]
ConvertTo-WPFGrid [[-InputObject] <PSObject>] [[-Title] <String>] [[-Timeout] <Int32>] [-Refresh] [-UseProfile]
[<CommonParameters>]
```

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

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.

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.

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.

## EXAMPLES

### EXAMPLE 1

```powershell
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"
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"
```

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.
Expand All @@ -41,13 +43,21 @@ Get the top 20 processes based on the value of the WorkingSet property and displ
```powershell
PS C:\> $vmhost = "CHI-HVR2"
PS C:\> Get-VM -computername $VMHost | Select Name,State,Uptime,
@{Name="AssignedMB";Expression={$_.MemoryAssigned/1mb -as \[int\]}},
@{Name="DemandMB";Expression={$_.MemoryDemand/1mb -as \[int\]}} |
@{Name="AssignedMB";Expression={$_.MemoryAssigned/1mb -as [int]}},
@{Name="DemandMB";Expression={$_.MemoryDemand/1mb -as [int]}} |
ConvertTo-WPFGrid -title "VM Report $VMHost" -timeout 20
```

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.

### EXAMPLE 3

```powershell
PS C:\> Get-VMData -host CHI-HVR2 | ConvertTo-WPFGrid -title "VM Data" -refresh -timeout 60 -useprofile
```

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.

## PARAMETERS

### -InputObject
Expand Down Expand Up @@ -114,6 +124,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -UseProfile
Load your PowerShell profiles into the background runspace.
```yaml
Type: SwitchParameter
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
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).
Expand Down
Loading

0 comments on commit cede9f6

Please sign in to comment.