-
Notifications
You must be signed in to change notification settings - Fork 511
Added Pester, ShouldProcess and Calculated Property PS Snippets #1764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Pester, ShouldProcess and Calculated Property PS Snippets #1764
Conversation
snippets/PowerShell.json
Outdated
"body": [ | ||
"@{name='${1:PropertyName}';expression={\\$_.${2:PropertyValue}}}$0" | ||
], | ||
"description": "Creates a PSCustomObject" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought there was already a PSCustomObject
snippet in this file. Is there not?
Also, isn't this just a hashtable
, not a true PSCustomObject
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woops. Thats my lazy copy paste it's a calculated property for use with select-object.
I'll update when back on the laptop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the description for the calculated property @TylerLeonhardt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry can you give me an example of this? I'm having a hard time seeing the scenario.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Linked from the Select-Object
docs:
-Property
Specifies the properties to select. These properties are added as NoteProperty members to the output objects. Wildcards are permitted.
The value of the Property parameter can be a new calculated property. To create a calculated, property, use a hash table. Valid keys are:
Name (or Label) <string>
Expression <string> or <script block>
Get-Process | Select-Object -Property ProcessName,@{Name="Start Day"; Expression = {$_.StartTime.DayOfWeek}}
ProcessName StartDay
---- --------
alg Wednesday
ati2evxx Wednesday
ati2evxx Thursday
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say it's used quite a bit when working with Active Directory.
Get-ADUser -Identity brettmillerb -properties manager | Select-Object -Property @(
@{name = 'Manager'; expression = { Get-ADUser -identity $_.Manager | Select-Object -ExpandProperty samaccountname }}
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I see now! Thanks for the explanation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny nit on the description so it's a little more informative. Otherwise LGTM!
Co-Authored-By: brettmillerb <[email protected]>
I updated the calculated property snippet to include the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks for contributing @brettmillerb! |
…rShell#1764) * Added Calculated Property and ShouldProcess Snippets * Added Pester Describe, Context & It Snippets * Placeholder Rename for calc property snippet * Fixed description for Calculated Property * Calc Property Enhanced Description Co-Authored-By: brettmillerb <[email protected]> * Amended the tab stop for calc-property to include .
* Added Calculated Property and ShouldProcess Snippets * Added Pester Describe, Context & It Snippets * Placeholder Rename for calc property snippet * Fixed description for Calculated Property * Calc Property Enhanced Description Co-Authored-By: brettmillerb <[email protected]> * Amended the tab stop for calc-property to include .
PR Summary
Added snippets for the following:
Select-Object -Property
If Should Process
for quickly addingif ($PSCmdlet.ShouldProcess("Target", "Operation")) {...}
PR Checklist
Note: Tick the boxes below that apply to this pull request by putting an
x
between the square brackets.Please mark anything not applicable to this PR
NA
.WIP:
to the beginning of the title and remove the prefix when the PR is ready