-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.ps1
142 lines (111 loc) · 3.52 KB
/
demo.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
return "This is a demo script file."
<#
My contact information
https://jdhitsolutions.github.io
#>
<#
Terminology
cmdlet: a powershell command
function: a powershell command defined in a script
script: a file containing powershell commands
module: a collection of cmdlets, functions, and other resources
toolmaking: the process of creating cmdlets, functions, and modules
#>
<#
Toolmaking decisions and planning
- what is the purpose of the tool?
- Who will use the tools?
- What is their expectation?
- Plan for the unexpected.
- You don't know how or where parameter values will come from.
- You can't predict every use case
- Plan for the pipeline
#>
#region start with a command
Get-WinEvent -LogName System -MaxEvents 20 -ComputerName $env:COMPUTERNAME
#endregion
#region scripts
#basic script
psedit .\basicscript.ps1
.\basicscript.ps1 -LogName application
#parameterized script
psedit .\paramscript.ps1
.\paramscript.ps1 -LogName System -Count 25 -path c:\temp | invoke-item
#endregion
#region functions
psedit .\basic-function.ps1
#load the function
. .\basic-function.ps1
help Get-CriticalEventLogEntry
Get-CriticalEventLogEntry -LogName application -Count 5
psedit .\Get-CriticalEventLogEntry.ps1
#load the function
. .\Get-CriticalEventLogEntry.ps
help gcel
"dom1","srv1","srv2" | gcel -LogName system -Count 10 -verbose -ov l | Out-GridView
psedit .\Get-LastBoot.ps1
. .\Get-LastBoot.ps1
$r = "srv1","srv2","dom2" | Get-LastBoot -verbose
$r
#endregion
#region modules
# module terms and basics
$env:PSModulePath -split ';'
# New-Item -name PSTools -Path . -ItemType Directory
cd .\PSTools
#create my module structure
'en-US', 'docs', 'functions', 'tests', 'formats', 'types' |
Where {-Not (Test-Path $_ )} | ForEach-Object {
New-Item -Name $_ -path . -ItemType Directory
}
# copy ..\Get-CriticalEventLogEntry.ps1 -Destination .\functions\
# copy ..\Get-LastBoot.ps1 -Destination .\functions\
#create the module file
New-Item -Name PSTools.psm1 -ItemType File
psedit .\PSTools.psm1
#create the manifest
help New-ModuleManifest
#parameter hashtable to splat to New-ModuleManifest
$paramHash = @{
Path = '.\PSTools.psd1'
Author = 'Jeff Hicks'
Description = 'TCSMUG PowerShell Tools'
RootModule = 'PSTools.psm1'
FunctionsToExport = 'Get-LastBoot', 'Get-PSTools', 'Get-CriticalEventLogEntry'
}
New-ModuleManifest @paramHash
psedit .\PSTools.psd1
#test the module
Import-Module .\PSTools.psd1 -force
Get-PSTools
Get-LastBoot
help Get-LastBoot
#create help docs
# Install-Module Platyps
Get-Command -module Platyps
New-MarkdownHelp -Module PSTools -OutputFolder .\docs
#update existing help
Update-MarkdownHelp -Path .\docs\Get-LastBoot.md
#create formatting file
# Install-Module PSScriptTools
$r = Get-LastBoot
$r | New-PSFormatXML -path .\formats\PSLastBootInfo.format.ps1xml -GroupBy Computername -Properties LastBoot,Uptime
#Create an additional List view
$r | New-PSFormatXML -Properties OS,Uptime -ViewName OS -FormatType List -GroupBy Computername -append -Path .\formats\PSLastBootInfo.format.ps1xml
#I have tweaked this file
psedit .\formats\PSLastBootInfo.format.ps1xml
#create external help
New-ExternalHelp -Path .\docs -OutputPath .\en-US -force
Import-Module .\PSTools.psd1 -force
help Get-LastBoot -Full
<#
other files:
changelog
Import-Module ChangelogManagement
New-ChangeLog -path .\PSTools\CHANGELOG.md
Use Add-ChangeLogData to add entries and
Update-ChangeLog to set a new release
license file
Create README.md
#>
#endregion