I am trying to extend the type of a custom object using a custom types.ps1xml file. The file works and extends many types the way I want.
I have been able to extend a custom type with a NoteProperty which has a boolean value of $true. All I want to be able to do now is add a NoteProperty to a different type with a TypeName value of System.Boolean and a Value of $false. My problem is that the property is always interpreted as a string and when cast as a TypeName of System.Boolean, it ALWAYS returns $true, because any non zero-length string returns $true.
I’m typing this on my phone and in a hurry to get back to work, but the pertinent parts of the ps1xml file are:
My.Custom.Object PSIsContainer System.Boolean True
That correctly results in a NoteProperty that reflects a Boolean value of $true. However, if I change the value to false, or 0, or null, or ‘’, or “”, or $false, or [bool]0, or any other feasible value with or without quotes or with or without $ or inside of $() or with escaped quotes or characters; it ALWAYS returns as a Boolean value of $true. If I leave blank it gives me an error when loading the xml, so that doesn’t work either. If I change the to something else, like a System.IO.File or whatever, it actually converts the value of “false” to a file object named “false”, or to whatever type I identify in the . So clearly it works as intended, except I cannot assign a bool value of $false. No matter what I do. If I leave out altogether it defaults to a System.String and that doesn’t help me.
If you look at Get-Member for a file or directory you will see the corresponding NoteProperty of PSIsContainer equal to a System.Boolean value of $true or $false, depending, and my output when set to true is exactly the same as the default directory object.
Mind you, the object I’m setting this property on is a custom object that doesn’t have any conflicting or existing property with that name or value. And it doesn’t matter if I change the. And to something else, like “IsAwesome”; it still doesn’t work for $false. I tried searching in the existing types.ps1xml and format.ps1xml and there is no hint at how they do it. I’ve searched online extensively for days, and even looked at some textbooks on Powershell to no avail.
Can someone please help me!?