You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-40Lines changed: 82 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,21 +6,24 @@ This PowerShell module contains a number of functions you might use to enhance y
6
6
The current release is [PSScriptTools-v1.0.1](https://github.com/jdhitsolutions/PSScriptTools/archive/v1.0.1.zip)
7
7
8
8
You can also install this from the PowerShell Gallery:
9
-
```
9
+
10
+
```powershell
10
11
Install-Module PSScriptTools
11
12
```
13
+
12
14
or in PowerShell Core:
13
-
```
15
+
16
+
```powershell
14
17
Install-Module PSScriptTools -scope currentuser
15
18
```
16
19
17
-
18
20
Please post any questions, problems or feedback in Issues. Any input is greatly appreciated.
19
21
20
22
## Add-Border
23
+
21
24
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.
This command will provide a summary of relevant information for the current user in a PowerShell Session. You might use this to troubleshoot an end-user problem running a script or command.
33
37
34
-
```
38
+
```powershell
35
39
PS C:\> Get-PSWho
36
40
37
41
User : COWPC\Jeff
@@ -46,10 +50,12 @@ WSMan : 3.0
46
50
ExecutionPolicy : RemoteSigned
47
51
Culture : en-US
48
52
```
53
+
49
54
## New-CustomFileName
55
+
50
56
This command will generate a custom file name based on a template string that you provide.
You can create a template string using any of these variables. Most of these should be self-explanatory
61
67
62
-
- %username
68
+
- %username
63
69
- %computername
64
-
- %year - 4 digit year
65
-
- %yr - 2 digit year
66
-
- %monthname - The abbreviated month name
67
-
- %month - The month number
68
-
- %dayofweek - The full name of the week day
69
-
- %day
70
-
- %hour
71
-
- %minute
72
-
- %time
73
-
- %string - A random string
74
-
- %guid
70
+
- %year - 4 digit year
71
+
- %yr - 2 digit year
72
+
- %monthname - The abbreviated month name
73
+
- %month - The month number
74
+
- %dayofweek - The full name of the week day
75
+
- %day
76
+
- %hour
77
+
- %minute
78
+
- %time
79
+
- %string - A random string
80
+
- %guid
75
81
76
82
You can also insert a random number using %### with a # character for each digit. If you want a 2 digit random number use %##. If you want 6 digits, use %######.
77
83
78
84
## New-RandomFileName
85
+
79
86
Create a new random file name. The default is a completely random name including the extension.
80
-
```
87
+
88
+
```powershell
81
89
PS C:\> new-randomfilename
82
90
fykxecvh.ipw
83
91
```
84
-
But you can specify an extentions.
85
-
```
92
+
93
+
But you can specify an extension.
94
+
95
+
```powershell
86
96
PS C:\> new-randomfilename -extension dat
87
97
emevgq3r.dat
88
98
```
99
+
89
100
Optionally you can create a random file name using the TEMP folder or your HOME folder. On Windows platforms this will default to your Documents folder.
This command is designed to be used within your functions and scripts to make it easier to write a detailed message that you can use as verbose output. The assumption is that you are using an advanced function with a Begin, Process and End scriptblocks. You can create a detailed message to indicate what part of the code is being executed. The output will include a full time stamp, although you can shorten it to be only a time string which includes a millisecond value.
101
114
115
+
This command is designed to be used within your functions and scripts to make it easier to write a detailed message that you can use as verbose output. The assumption is that you are using an advanced function with a Begin, Process and End scriptblocks. You can create a detailed message to indicate what part of the code is being executed. The output can be configured to include a datetime stamp or just the time.
116
+
117
+
```powershell
118
+
PS C:\> write-detail "Getting file information" -Prefix Process -Date
119
+
9/15/2018 11:42:43 [PROCESS] Getting file information
102
120
```
103
-
PS C:\>write-detail "Getting file information" -Prefix Process -NoDate
104
-
02:39:18:4874 [PROCESS] Getting file information
105
-
```
121
+
106
122
In a script you might use it like this:
107
-
```
123
+
124
+
```powershell
108
125
Begin {
109
-
Write-Detail "Starting $($myinvocation.mycommand)" -Prefix begin | Write-Verbose
126
+
Write-Detail "Starting $($myinvocation.mycommand)" -Prefix begin -time | Write-Verbose
110
127
$tabs = "`t" * $tab
111
-
Write-Detail "Using a tab of $tab" -Prefix BEGIN | Write-Verbose
128
+
Write-Detail "Using a tab of $tab" -Prefix BEGIN -time | Write-Verbose
112
129
} #begin
113
130
```
114
131
115
132
## Out-VerboseTee
133
+
116
134
This command is intended to let you see your verbose output and write the verbose messages to a log file. It will only work if the verbose pipeline is enabled, usually when your command is run with -Verbose. This function is designed to be used within your scripts and functions. You either have to hard code a file name or find some other way to define it in your function or control script. You could pass a value as a parameter or set it as a PSDefaultParameterValue.
117
135
118
136
This command has an alias of Tee-Verbose.
119
137
120
-
```
138
+
```powershell
121
139
Begin {
122
140
$log = New-RandomFilename -useTemp -extension log
123
141
Write-Detail "Starting $($myinvocation.mycommand)" -Prefix begin | Tee-Verbose $log
@@ -126,9 +144,11 @@ Begin {
126
144
$data = @()
127
145
} #begin
128
146
```
147
+
129
148
When the command is run with -Verbose you will see the verbose output and it will be saved to the specified log file.
130
149
131
150
## Out-ConditionalColor
151
+
132
152
This command is designed to take pipeline input and display it in a colorized format,based on a set of conditions. Unlike Write-Host which doesn't write to the pipeline, this command will write to the pipeline.
133
153
134
154
You can use a simple hashtable to define a color if the given property matches the hashtable key.
@@ -141,11 +161,14 @@ Or you can specify an ordered hashtable for more complex processing.
141
161
This command doesn't always work depending on the type of object you pipe to it. The problem appears to be related to the formatting system. Development and testing is ongoing.
142
162
143
163
## Copy-Command
164
+
144
165
This command will copy a PowerShell command, including parameters and help to a new user-specified command. You can use this to create a "wrapper" function or to easily create a proxy function. The default behavior is to create a copy of the command complete with the original comment-based help block.
145
166
146
167
## Format-Functions
168
+
147
169
A set of simple commands to make it easier to format values.
@@ -182,36 +210,48 @@ You can also get detailed information.
182
210

183
211
184
212
Results will vary depending on whether you are running Windows PowerShell or PowerShell Core.
213
+
185
214
## Out-More
215
+
186
216
This command provides a PowerShell alternative to the cmd.exe MORE command, which doesn't work in the PowerShell ISE. When you have screens of information, you can page it with this function.
187
-
```
217
+
218
+
```powershell
188
219
get-service | out-more
189
220
```
221
+
190
222

191
223
192
224
This also works in PowerShell Core.
193
225
194
226
## Invoke-InputBox
227
+
195
228
This function is a graphical replacement for Read-Host. It creates a simple WPF form that you can use to get user input. The value of the text box will be written to the pipeline.
196
-
```
229
+
230
+
```powershell
197
231
$name = Invoke-InputBox -Prompt "Enter a user name" -Title "New User Setup"
198
232
```
233
+
199
234

200
235
201
236
You can also capture a secure string.
202
-
```
237
+
238
+
```powershell
203
239
Invoke-Inputbox -Prompt "Enter a password for $Name" -AsSecureString -BackgroundColor red
204
240
```
241
+
205
242

206
243
207
244
This example also demonstrates that you can change form's background color.
208
245
This function will **not** work in PowerShell Core.
209
246
210
247
## ToDo
248
+
211
249
Because this module is intended to make scripting easier for you, it adds options to insert ToDo statements into PowerShell files. If you are using the PowerShell ISE or VS Code and import this module, it will add the capability to insert a line like this:
212
-
```
250
+
251
+
```yaml
213
252
# [12/13/2017 16:52:40] TODO: Add parameters
214
253
```
254
+
215
255
In the PowerShell ISE, you will get a new menu under Add-Ons
216
256
217
257

@@ -221,9 +261,11 @@ You can use the menu or keyboard shortcut which will launch an input box.
221
261

222
262
223
263
The comment will be inserted at the current cursor location.
264
+
224
265
In VS Code, access the command palette (Ctrl+Shift+P) and then "PowerShell: Show Additional Commands from PowerShell Modules". Select "Insert ToDo" from the list and you'll get the same input box. Note that this will only work for PowerShell files.
225
266
226
267
### Compatibility
268
+
227
269
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.
0 commit comments