Skip to content

Commit 7a889bd

Browse files
see change log for v1.3.0
1 parent 3a79ce1 commit 7a889bd

38 files changed

Lines changed: 4291 additions & 1507 deletions

Add-Border.ps1

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -6,63 +6,6 @@ originally published at
66
77
#>
88
Function Add-Border {
9-
<#
10-
.Synopsis
11-
Create a text border around a string.
12-
13-
.Description
14-
This command will create a character or text based border around a line of text. You might use this to create a formatted text report or to improve the display of information to the screen.
15-
16-
.Parameter Text
17-
A single line of text that will be wrapped in a border.
18-
19-
.Parameter Textblock
20-
A multiline block of text. You might want to trim blank lines from the beginning, end or both.
21-
22-
.Parameter Character
23-
The character to use for the border. It must be a single character.
24-
25-
.Parameter InsertBlanks
26-
Insert blank lines before and after the text. The default behavior is to create a border box close to the text. See examples.
27-
28-
.Parameter $Tab
29-
Insert the specified number of tab characters before the result.
30-
31-
.Example
32-
PS C:\> add-border "PowerShell Wins!"
33-
********************
34-
* PowerShell Wins! *
35-
********************
36-
37-
.Example
38-
PS C:\> add-border "PowerShell Wins!" -tab 1
39-
40-
********************
41-
* PowerShell Wins! *
42-
********************
43-
44-
Note that this example may not format properly in the console.
45-
.Example
46-
PS C:\> add-border "PowerShell Wins!" -character "-" -insertBlanks
47-
--------------------
48-
- -
49-
- PowerShell Wins! -
50-
- -
51-
--------------------
52-
53-
.Example
54-
PS C:\> add-border -textblock (get-service win* | out-string).trim()
55-
**********************************************************************
56-
* Status Name DisplayName *
57-
* ------ ---- ----------- *
58-
* Stopped WinDefend Windows Defender Antivirus Service *
59-
* Running WinHttpAutoProx... WinHTTP Web Proxy Auto-Discovery Se... *
60-
* Running Winmgmt Windows Management Instrumentation *
61-
* Stopped WinRM Windows Remote Management (WS-Manag... *
62-
**********************************************************************
63-
64-
Create a border around the output of a Get-Service command.
65-
#>
669
[CmdletBinding(DefaultParameterSetName = "single")]
6710
Param(
6811
# The string of text to process

ConvertTo-Markdown.ps1

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
#requires -version 5.0
2+
Function ConvertTo-Markdown {
3+
<#
4+
.Synopsis
5+
Convert pipeline output to a markdown document.
6+
.Description
7+
This command is designed to accept pipelined output and create a markdown document. The pipeline output will formatted as a text block. You can optionally define a title, content to appear before the output and content to appear after the output.
8+
9+
The command does not create a text file. You need to pipe results from this command to a cmdlet like Out-File or Set-Content. See examples.
10+
.Parameter Title
11+
Specify a top level title. You do not need to include any markdown.
12+
.Parameter PreContent
13+
Enter whatever content you want to appear before converted input. You can use whatever markdown you wish.
14+
.Parameter PostContent
15+
Enter whatever content you want to appear after converted input. You can use whatever markdown you wish.
16+
.Parameter Width
17+
Specify the document width. Depending on what you intend to do with the markdown from this command you may want to adjust this value.
18+
.Example
19+
PS C:\> Get-Service Bits,Winrm | Convertto-Markdown -title "Service Check" -precontent "## $($env:computername)" -postcontent "_report $(Get-Date)_"
20+
21+
# Service Check
22+
23+
## THINK51
24+
25+
```text
26+
27+
Status Name DisplayName
28+
------ ---- -----------
29+
Running Bits Background Intelligent Transfer Ser...
30+
Running Winrm Windows Remote Management (WS-Manag...
31+
```
32+
33+
_report 07/20/2018 18:40:52_
34+
35+
.Example
36+
PS C:\> Get-Service Bits,Winrm | Convertto-Markdown -title "Service Check" -precontent "## $($env:computername)" -postcontent "_report $(Get-Date)_" | Out-File c:\work\svc.md
37+
38+
Re-run the previous command and save output to a file.
39+
40+
.Example
41+
PS C:\> $computers = "srv1","srv2","srv4"
42+
PS C:\> $Title = "System Report"
43+
PS C:\> $footer = "_report run $(Get-Date) by $($env:USERDOMAIN)\$($env:USERNAME)_"
44+
PS C:\> $sb = {
45+
>> $os = get-ciminstance -classname win32_operatingsystem -property caption,lastbootUptime
46+
>> [PSCustomObject]@{
47+
>> PSVersion = $PSVersionTable.PSVersion
48+
>> OS = $os.caption
49+
>> Uptime = (Get-Date) - $os.lastbootUpTime
50+
>> SizeFreeGB = (Get-Volume -DriveLetter C).SizeRemaining /1GB
51+
>> }
52+
>> }
53+
PS C:\> $out = Convertto-Markdown -title $Title
54+
PS C:\> foreach ($computer in $computers) {
55+
>> $out+= Invoke-command -scriptblock $sb -ComputerName $computer -HideComputerName |
56+
>> Select-Object -Property * -ExcludeProperty RunspaceID |
57+
>> ConvertTo-Markdown -PreContent "## $($computer.toUpper())"
58+
>> }
59+
PS C:\>$out += ConvertTo-Markdown -PostContent $footer
60+
PS C:\>$out | set-content c:\work\report.md
61+
62+
Here is an example that create a series of markdown fragments for each computer and at the end creates a markdown document.
63+
.Link
64+
Convertto-HTML
65+
.Link
66+
Out-File
67+
68+
.Notes
69+
Learn more about PowerShell: https://jdhitsolutions.com/blog/essential-powershell-resources/
70+
71+
.Inputs
72+
[object]
73+
#>
74+
75+
[cmdletbinding()]
76+
[outputtype([string[]])]
77+
[alias('ctm')]
78+
Param(
79+
[Parameter(Position = 0, ValueFromPipeline)]
80+
[object]$Inputobject,
81+
[Parameter()]
82+
[string]$Title,
83+
[string[]]$PreContent,
84+
[string[]]$PostContent,
85+
[ValidateScript( {$_ -ge 10})]
86+
[int]$Width = 80
87+
)
88+
89+
Begin {
90+
Write-Verbose "[BEGIN ] Starting $($myinvocation.MyCommand)"
91+
#initialize an array to hold incoming data
92+
$data = @()
93+
94+
#initialize an empty here string for markdown text
95+
$Text = @"
96+
97+
"@
98+
If ($title) {
99+
Write-Verbose "[BEGIN ] Adding Title: $Title"
100+
$Text += "# $Title`n`n"
101+
}
102+
If ($precontent) {
103+
Write-Verbose "[BEGIN ] Adding Precontent"
104+
$Text += $precontent
105+
$text += "`n`n"
106+
}
107+
108+
} #begin
109+
110+
Process {
111+
#add incoming objects to data array
112+
Write-Verbose "[PROCESS] Adding processed object"
113+
$data += $Inputobject
114+
115+
} #process
116+
End {
117+
#add the data to the text
118+
if ($data) {
119+
#convert data to strings and trim each line
120+
Write-Verbose "[END ] Converting data to strings"
121+
[string]$trimmed = (($data | Out-String -Width $width).split("`n")).ForEach( {"$($_.trimend())`n"})
122+
Write-Verbose "[END ] Adding to markdown"
123+
$text += @"
124+
``````text
125+
$($trimmed.trimend())
126+
``````
127+
128+
"@
129+
}
130+
131+
If ($postcontent) {
132+
Write-Verbose "[END ] Adding postcontent"
133+
$text += "`n"
134+
$text += $postcontent
135+
}
136+
#write the markdown to the pipeline
137+
$text
138+
Write-Verbose "[END ] Ending $($myinvocation.MyCommand)"
139+
} #end
140+
141+
} #close ConvertTo-Markdown

ConvertTo-WPFGrid.ps1

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#requires -version 5.0
2+
3+
# ToDo: Add option to use last position for Top and Left properties of the form or provide that as an option
4+
# ToDo: Add statusbar for timer countdown and other information
5+
6+
Function ConvertTo-WPFGrid {
7+
8+
[cmdletbinding()]
9+
[Alias("cwg")]
10+
[outputtype("none")]
11+
12+
Param(
13+
[Parameter(ValueFromPipeline)]
14+
[psobject]$InputObject,
15+
[string]$Title = "ConvertTo-WPFGrid",
16+
[ValidateScript( {$_ -ge 5})]
17+
[int]$Timeout,
18+
[int]$Width = 1024,
19+
[int]$Height = 768,
20+
[switch]$CenterScreen
21+
)
22+
23+
Begin {
24+
25+
Write-Verbose "Starting $($MyInvocation.MyCommand)"
26+
27+
# ! It may not be necessary to add these types but it doesn't hurt to include them
28+
Add-Type -AssemblyName PresentationFramework
29+
Add-Type -assemblyName PresentationCore
30+
Add-Type -AssemblyName WindowsBase
31+
32+
# define a timer to automatically dismiss the form. The timer uses a 5 second interval tick
33+
if ($Timeout -gt 0) {
34+
Write-Verbose "Creating a timer"
35+
$timer = new-object System.Windows.Threading.DispatcherTimer
36+
$terminate = (Get-Date).AddSeconds($timeout)
37+
Write-verbose "Form will close at $terminate"
38+
$timer.Interval = [TimeSpan]"0:0:5.00"
39+
40+
$timer.add_tick( {
41+
if ((Get-Date) -ge $terminate) {
42+
$timer.stop()
43+
$form.Close()
44+
}
45+
})
46+
}
47+
48+
Write-Verbose "Defining form: $Title ($width x $height)"
49+
50+
$form = New-Object System.Windows.Window
51+
#define what it looks like
52+
$form.Title = $Title
53+
$form.Height = $Height
54+
$form.Width = $Width
55+
56+
if ($CenterScreen) {
57+
Write-Verbose "Form will be center screen"
58+
$form.WindowStartupLocation = [System.Windows.WindowStartupLocation]::CenterScreen
59+
}
60+
#define a handler when the form is loaded. The scriptblock uses variables defined later
61+
#in the script
62+
$form.add_Loaded( {
63+
foreach ($col in $datagrid.Columns) {
64+
#because of the way I am loading data into the grid
65+
#it appears I need to set the sorting on each column
66+
$col.CanUserSort = $True
67+
$col.SortMemberPath = $col.Header
68+
}
69+
$datagrid.Items.Refresh()
70+
$form.focus
71+
})
72+
#Create a stack panel to hold the datagrid
73+
$stack = New-object System.Windows.Controls.StackPanel
74+
75+
#create a datagrid
76+
$datagrid = New-Object System.Windows.Controls.DataGrid
77+
78+
$datagrid.VerticalAlignment = "Bottom"
79+
#adjust the size of the grid based on the form dimensions
80+
$datagrid.Height = $form.Height - 50
81+
$datagrid.Width = $form.Width - 50
82+
$datagrid.CanUserSortColumns = $True
83+
$datagrid.CanUserResizeColumns = $True
84+
$datagrid.CanUserReorderColumns = $True
85+
$datagrid.AutoGenerateColumns = $True
86+
#enable alternating color rows
87+
$datagrid.AlternatingRowBackground = "gainsboro"
88+
89+
$stack.AddChild($datagrid)
90+
$form.AddChild($stack)
91+
92+
#initialize an array to hold all processed objects
93+
$data = @()
94+
} #begin
95+
96+
Process {
97+
#add each incoming object to the data array
98+
$data += $Inputobject
99+
} #process
100+
101+
End {
102+
Write-Verbose "Preparing form"
103+
$DataGrid.ItemsSource = $data
104+
105+
#show the form
106+
If ($Timeout -gt 0) {
107+
Write-Verbose "Starting timer"
108+
$timer.IsEnabled = $True
109+
$Timer.Start()
110+
}
111+
112+
Write-Verbose "Displaying form"
113+
$form.ShowDialog() | Out-Null
114+
115+
write-verbose "Ending $($MyInvocation.MyCommand)"
116+
117+
} #end
118+
119+
} #close function

Copy-Command.ps1

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

2+
#region private functions
23
Function Get-CommandParameter {
34
[cmdletbinding()]
5+
46
Param(
57
[Parameter(ValueFromPipeline, Mandatory, HelpMessage = "Enter the name of a command")]
68
[ValidateNotNullOrEmpty()]
@@ -88,10 +90,13 @@ Function Get-CommandMetadata {
8890

8991
} #close Get-CommandMetadata
9092

91-
93+
#endregion
9294
Function Copy-Command {
9395

9496
[cmdletbinding()]
97+
[alias("cc")]
98+
[OutputType([string[]])]
99+
95100
Param(
96101
[Parameter(Position = 0, Mandatory, HelpMessage = "Enter the name of a PowerShell command")]
97102
[ValidateNotNullorEmpty()]

0 commit comments

Comments
 (0)