Skip to content

Commit 9a678c0

Browse files
Fix incorrect case/capitalization in reference documents (37/38) (#11945)
* Fix incorrect case/capitalization in ref docs This ensures the following components have the correct/consistent case throughout the reference documentation: Preference variable, PS environment variable, PS drive, PS provider, PS command name, PS command argument, PS module, PS file extension, PS host name/application, #Requires statement, parameter name, about_* topic, member name, scope modifier, keyword, operator, calculated property key/value, attribute, type accelerator, type literal/name, WMI namespace/class, variable name, special character, comment-based help keyword, product/company name, Windows drive letter/directory, Windows/Unix environment variable In addition, changes include fixes to incorrect terminology (e.g., referring to a keyword as a command) and formatting of PS syntax elements (non-exhaustive). * Fix merge mistake/typo
1 parent 00cf5c0 commit 9a678c0

40 files changed

+240
-238
lines changed

reference/docs-conceptual/learn/deep-dives/everything-about-if.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ It evaluates to `$true` if there's a returned process and `$false` if there isn'
425425
perfectly valid to use pipeline expressions or other PowerShell statements like this:
426426

427427
```powershell
428-
if ( Get-Process | Where Name -eq Notepad )
428+
if ( Get-Process | where Name -EQ Notepad )
429429
```
430430

431431
These expressions can be combined with each other with the `-and` and `-or` operators, but you may
@@ -452,7 +452,7 @@ in diving deeper, I have an article about [everything you wanted to know about $
452452
I almost forgot to add this one until [Prasoon Karunan V][Prasoon Karunan V] reminded me of it.
453453

454454
```powershell
455-
if ($process=Get-Process notepad -ErrorAction ignore) {$process} else {$false}
455+
if ($process=Get-Process notepad -ErrorAction Ignore) {$process} else {$false}
456456
```
457457

458458
Normally when you assign a value to a variable, the value isn't passed onto the pipeline or
@@ -643,7 +643,7 @@ fall into the `$snowSqlParam` in the correct place. Same holds true for the `$Pa
643643
## Simplify complex operations
644644

645645
It's inevitable that you run into a situation that has way too many comparisons to check and your
646-
`If` statement scrolls way off the right side of the screen.
646+
`if` statement scrolls way off the right side of the screen.
647647

648648
```powershell
649649
$user = Get-ADUser -Identity $UserName

reference/docs-conceptual/learn/deep-dives/everything-about-null.md

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ property, you get a `$null` value like you would for an undefined variable. It d
126126
variable is `$null` or an actual object in this case.
127127

128128
```powershell
129-
PS> $null -eq $undefined.some.fake.property
129+
PS> $null -eq $undefined.Some.Fake.Property
130130
True
131131
132132
PS> $date = Get-Date
133-
PS> $null -eq $date.some.fake.property
133+
PS> $null -eq $date.Some.Fake.Property
134134
True
135135
```
136136

@@ -140,10 +140,10 @@ Calling a method on a `$null` object throws a `RuntimeException`.
140140

141141
```powershell
142142
PS> $value = $null
143-
PS> $value.toString()
143+
PS> $value.ToString()
144144
You cannot call a method on a null-valued expression.
145145
At line:1 char:1
146-
+ $value.tostring()
146+
+ $value.ToString()
147147
+ ~~~~~~~~~~~~~~~~~
148148
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
149149
+ FullyQualifiedErrorId : InvokeMethodOnNull
@@ -246,9 +246,9 @@ I ran into this issue when refactoring some code a few days ago. It had a basic
246246
this.
247247

248248
```powershell
249-
if ( $object.property )
249+
if ( $object.Property )
250250
{
251-
$object.property = $value
251+
$object.Property = $value
252252
}
253253
```
254254

@@ -259,40 +259,40 @@ the property but it was a blank string value. This prevented it from ever gettin
259259
previous logic. So I added a proper `$null` check and everything worked.
260260

261261
```powershell
262-
if ( $null -ne $object.property )
262+
if ( $null -ne $object.Property )
263263
{
264-
$object.property = $value
264+
$object.Property = $value
265265
}
266266
```
267267

268268
It's little bugs like these that are hard to spot and make me aggressively check values for `$null`.
269269

270270
## $null.Count
271271

272-
If you try to access a property on a `$null` value, that the property is also `$null`. The `count`
272+
If you try to access a property on a `$null` value, that the property is also `$null`. The `Count`
273273
property is the exception to this rule.
274274

275275
```powershell
276276
PS> $value = $null
277-
PS> $value.count
277+
PS> $value.Count
278278
0
279279
```
280280

281-
When you have a `$null` value, then the `count` is `0`. This special property is added by
281+
When you have a `$null` value, then the `Count` is `0`. This special property is added by
282282
PowerShell.
283283

284284
### [PSCustomObject] Count
285285

286-
Almost all objects in PowerShell have that count property. One important exception is the
287-
`[PSCustomObject]` in Windows PowerShell 5.1 (This is fixed in PowerShell 6.0). It doesn't have a
288-
count property so you get a `$null` value if you try to use it. I call this out here so that you
289-
don't try to use `.Count` instead of a `$null` check.
286+
Almost all objects in PowerShell have that `Count` property. One important exception is the
287+
`[pscustomobject]` in Windows PowerShell 5.1 (This is fixed in PowerShell 6.0). It doesn't have a
288+
`Count` property so you get a `$null` value if you try to use it. I call this out here so that you
289+
don't try to use `Count` instead of a `$null` check.
290290

291291
Running this example on Windows PowerShell 5.1 and PowerShell 6.0 gives you different results.
292292

293293
```powershell
294-
$value = [PSCustomObject]@{Name='MyObject'}
295-
if ( $value.count -eq 1 )
294+
$value = [pscustomobject]@{Name='MyObject'}
295+
if ( $value.Count -eq 1 )
296296
{
297297
"We have a value"
298298
}
@@ -318,19 +318,19 @@ required, the value is always `$null`. But if you place it inside an array, it's
318318
an empty array.
319319

320320
```powershell
321-
PS> $containempty = @( @() )
322-
PS> $containnothing = @($nothing)
323-
PS> $containnull = @($null)
321+
PS> $containEmpty = @( @() )
322+
PS> $containNothing = @($nothing)
323+
PS> $containNull = @($null)
324324
325-
PS> $containempty.count
325+
PS> $containEmpty.Count
326326
0
327-
PS> $containnothing.count
327+
PS> $containNothing.Count
328328
0
329-
PS> $containnull.count
329+
PS> $containNull.Count
330330
1
331331
```
332332

333-
You can have an array that contains one `$null` value and its `count` is `1`. But if you place
333+
You can have an array that contains one `$null` value and its `Count` is `1`. But if you place
334334
an empty array inside an array then it's not counted as an item. The count is `0`.
335335

336336
If you treat the enumerable null like a collection, then it's empty.
@@ -355,7 +355,7 @@ Depending on your code, you should account for the `$null` in your logic.
355355

356356
Either check for `$null` first
357357

358-
- Filter out null on the pipeline (`... | Where {$null -ne $_} | ...`)
358+
- Filter out null on the pipeline (`... | where {$null -ne $_} | ...`)
359359
- Handle it in the pipeline function
360360

361361
## foreach
@@ -372,7 +372,7 @@ foreach ( $node in $null )
372372
This saves me from having to `$null` check the collection before I enumerate it. If you have a
373373
collection of `$null` values, the `$node` can still be `$null`.
374374

375-
The foreach started working this way with PowerShell 3.0. If you happen to be on an older version,
375+
The `foreach` started working this way with PowerShell 3.0. If you happen to be on an older version,
376376
then this is not the case. This is one of the important changes to be aware of when back-porting
377377
code for 2.0 compatibility.
378378

@@ -420,7 +420,7 @@ it.
420420
function Do-Something
421421
{
422422
param(
423-
[String] $Value
423+
[string] $Value
424424
)
425425
}
426426
```
@@ -485,8 +485,8 @@ commands you use deal with the no results and error scenarios.
485485
## Initializing to $null
486486

487487
One habit that I have picked up is initializing all my variables before I use them. You are required
488-
to do this in other languages. At the top of my function or as I enter a foreach loop, I define all
489-
the values that I'm using.
488+
to do this in other languages. At the top of my function or as I enter a `foreach` loop, I define
489+
all the values that I'm using.
490490

491491
Here is a scenario that I want you to take a close look at. It's an example of a bug I had to chase
492492
down before.
@@ -498,7 +498,7 @@ function Do-Something
498498
{
499499
try
500500
{
501-
$result = Get-Something -ID $node
501+
$result = Get-Something -Id $node
502502
}
503503
catch
504504
{
@@ -521,7 +521,7 @@ to `$result`. It fails before the assignment so we don't even assign `$null` to
521521
variable. `$result` still contains the previous valid `$result` from other iterations.
522522
`Update-Something` to execute multiple times on the same object in this example.
523523

524-
I set `$result` to `$null` right inside the foreach loop before I use it to mitigate this issue.
524+
I set `$result` to `$null` right inside the `foreach` loop before I use it to mitigate this issue.
525525

526526
```powershell
527527
foreach ( $node in 1..6 )
@@ -557,7 +557,7 @@ function Do-Something
557557
{
558558
try
559559
{
560-
$result = Get-Something -ID $node
560+
$result = Get-Something -Id $node
561561
}
562562
catch
563563
{

reference/docs-conceptual/learn/deep-dives/everything-about-pscustomobject.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ better idea of what that means.
1818
1919
## Creating a PSCustomObject
2020

21-
I love using `[PSCustomObject]` in PowerShell. Creating a usable object has never been easier.
21+
I love using `[pscustomobject]` in PowerShell. Creating a usable object has never been easier.
2222
Because of that, I'm going to skip over all the other ways you can create an object but I need
2323
to mention that most of these examples are PowerShell v3.0 and newer.
2424

2525
```powershell
26-
$myObject = [PSCustomObject]@{
26+
$myObject = [pscustomobject]@{
2727
Name = 'Kevin'
2828
Language = 'PowerShell'
2929
State = 'Texas'
@@ -32,7 +32,7 @@ $myObject = [PSCustomObject]@{
3232

3333
This method works well for me because I use hashtables for just about everything. But there are
3434
times when I would like PowerShell to treat hashtables more like an object. The first place you
35-
notice the difference is when you want to use `Format-Table` or `Export-CSV` and you realize that a
35+
notice the difference is when you want to use `Format-Table` or `Export-Csv` and you realize that a
3636
hashtable is just a collection of key/value pairs.
3737

3838
You can then access and use the values like you would a normal object.
@@ -73,18 +73,18 @@ $myHashtable = @{
7373
State = 'Texas'
7474
}
7575
76-
$myObject = New-Object -TypeName PSObject -Property $myHashtable
76+
$myObject = New-Object -TypeName psobject -Property $myHashtable
7777
```
7878

7979
This way is quite a bit slower but it may be your best option on early versions of PowerShell.
8080

8181
### Saving to a file
8282

8383
I find the best way to save a hashtable to a file is to save it as JSON. You can import it back into
84-
a `[PSCustomObject]`
84+
a `[pscustomobject]`
8585

8686
```powershell
87-
$myObject | ConvertTo-Json -depth 1 | Set-Content -Path $Path
87+
$myObject | ConvertTo-Json -Depth 1 | Set-Content -Path $Path
8888
$myObject = Get-Content -Path $Path | ConvertFrom-Json
8989
```
9090

@@ -108,7 +108,7 @@ $myObject.ID
108108
You can also remove properties off of an object.
109109

110110
```powershell
111-
$myObject.psobject.properties.remove('ID')
111+
$myObject.psobject.Properties.Remove('ID')
112112
```
113113

114114
The `.psobject` is an intrinsic member that gives you access to base object metadata. For more
@@ -120,13 +120,13 @@ information about intrinsic members, see
120120
Sometimes you need a list of all the property names on an object.
121121

122122
```powershell
123-
$myObject | Get-Member -MemberType NoteProperty | Select -ExpandProperty Name
123+
$myObject | Get-Member -MemberType NoteProperty | select -ExpandProperty Name
124124
```
125125

126126
We can get this same list off of the `psobject` property too.
127127

128128
```powershell
129-
$myobject.psobject.properties.name
129+
$myobject.psobject.Properties.Name
130130
```
131131

132132
> [!NOTE]
@@ -163,7 +163,7 @@ from them.
163163

164164
```powershell
165165
$hashtable = @{}
166-
foreach( $property in $myobject.psobject.properties.name )
166+
foreach( $property in $myobject.psobject.Properties.Name )
167167
{
168168
$hashtable[$property] = $myObject.$property
169169
}
@@ -178,10 +178,10 @@ if( $null -ne $myObject.ID )
178178
```
179179

180180
But if the value could be `$null` you can check to see if it exists by checking the
181-
`psobject.properties` for it.
181+
`psobject.Properties` for it.
182182

183183
```powershell
184-
if( $myobject.psobject.properties.match('ID').Count )
184+
if( $myobject.psobject.Properties.Match('ID').Count )
185185
```
186186

187187
## Adding object methods
@@ -193,7 +193,7 @@ If you need to add a script method to an object, you can do it with `Add-Member`
193193
```powershell
194194
$ScriptBlock = {
195195
$hashtable = @{}
196-
foreach( $property in $this.psobject.properties.name )
196+
foreach( $property in $this.psobject.Properties.Name )
197197
{
198198
$hashtable[$property] = $this.$property
199199
}
@@ -236,21 +236,21 @@ Object variables hold a reference to the actual object. When you assign one obje
236236
variable, they still reference the same object.
237237

238238
```powershell
239-
$third = [PSCustomObject]@{Key=3}
239+
$third = [pscustomobject]@{Key=3}
240240
$fourth = $third
241241
$fourth.Key = 4
242242
```
243243

244244
Because `$third` and `$fourth` reference the same instance of an object, both `$third.key` and
245245
`$fourth.Key` are 4.
246246

247-
### psobject.copy()
247+
### psobject.Copy()
248248

249249
If you need a true copy of an object, you can clone it.
250250

251251
```powershell
252-
$third = [PSCustomObject]@{Key=3}
253-
$fourth = $third.psobject.copy()
252+
$third = [pscustomobject]@{Key=3}
253+
$fourth = $third.psobject.Copy()
254254
$fourth.Key = 4
255255
```
256256

@@ -267,14 +267,14 @@ obvious. First thing we need to do is give it a `PSTypeName`. This is the most c
267267
people do it:
268268

269269
```powershell
270-
$myObject.PSObject.TypeNames.Insert(0,"My.Object")
270+
$myObject.psobject.TypeNames.Insert(0,"My.Object")
271271
```
272272

273273
I recently discovered another way to do this from Redditor `u/markekraus`. He talks about this
274274
approach that allows you to define it inline.
275275

276276
```powershell
277-
$myObject = [PSCustomObject]@{
277+
$myObject = [pscustomobject]@{
278278
PSTypeName = 'My.Object'
279279
Name = 'Kevin'
280280
Language = 'PowerShell'
@@ -337,7 +337,7 @@ $TypeData = @{
337337
TypeName = 'My.Object'
338338
MemberType = 'ScriptProperty'
339339
MemberName = 'UpperCaseName'
340-
Value = {$this.Name.toUpper()}
340+
Value = {$this.Name.ToUpper()}
341341
}
342342
Update-TypeData @TypeData
343343
```
@@ -388,7 +388,7 @@ to the pipe when they shouldn't.
388388

389389
## Closing thoughts
390390

391-
The context of this was all about `[PSCustomObject]`, but a lot of this information applies to
391+
The context of this was all about `[pscustomobject]`, but a lot of this information applies to
392392
objects in general.
393393

394394
I have seen most of these features in passing before but never saw them presented as a collection of

0 commit comments

Comments
 (0)