First of all, you lack parentheses to call GetType. What you see is the MethodInfo describing the GetType method on [DayOfWeek]. To actually call GetType, you should do:
$a.GetType();
$b.GetType();
You should see that $a is a [DayOfWeek], and $b is a custom object generated by the Select-Object cmdlet to capture only the DayOfWeek property of a data object. Hence, it's an object with a DayOfWeek property only:
C:\> $b.DayOfWeek -eq $a
True
Answer from Cédric Rup on Stack OverflowFirst of all, you lack parentheses to call GetType. What you see is the MethodInfo describing the GetType method on [DayOfWeek]. To actually call GetType, you should do:
$a.GetType();
$b.GetType();
You should see that $a is a [DayOfWeek], and $b is a custom object generated by the Select-Object cmdlet to capture only the DayOfWeek property of a data object. Hence, it's an object with a DayOfWeek property only:
C:\> $b.DayOfWeek -eq $a
True
Select-Object creates a new psobject and copies the properties you requested to it. You can verify this with GetType():
PS > $a.GetType().fullname
System.DayOfWeek
PS > $b.GetType().fullname
System.Management.Automation.PSCustomObject
Powershell and Types
Variable naming
Set-content how write $variable as it is and not as variable
Removing the end of a Filename with Powershell
Try changing your Rename-Item to this
Rename-Item -NewName $($_.BaseName -replace ".{4}$") More on reddit.com Videos
Once upon a time I was a C/C++ programmer. I am trying to get my feet wet with PS to accomplish some maintenance tasks on my computer that might not justify either a command line or Windows app. The lack of typing in PS is really messing with my head. It seems as though variables can be created as any type and that "functions" in PS can return a wide variety of types.
How am I supposed to know what is in a variable if I cannot trace it back to its declaration and see a type?
Example question...
$filenames = Get-ChildItem -Path "D:\Brian's Stuff\Media\Data\Video\Santa Barbara\0001 - 0100\Santa Barbara 8493" -Filter *.mp4
So apparently this invocation of Get-ChildItem returns a collection. How do I know the collection type (is it an array? A linked list? An abstraction of a binary tree?) And what about the type of object being stored in the collection. How do I determine that without any variable typing? $filenames is a collection, but of what? And it all can change depending on what type of information I am asking Get-ChildItem for?
Maybe I need to find a strongly typed language. I don't get it. BTW I am literally 6 hours old with PS. Just started. Trying to learn only what I need to learn to get the job done. Don't intend to study the language out of intellectual curiousity.