I have an array of objects and am trying to manipulate it and am getting an error that the property RptFile does not exist. I have checked the spelling and everything and am baffled as to what is going on.
The code giving the error:
$AllContents | Where-Object {$_.RptFile -eq 'CB-Officer Trial New'}
AllContents | Get-Member returns:
TypeName: Selected.System.Management.Automation.PSCustomObject
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
RptFile NoteProperty System.String RptFile=ABL - Branch5206 Daily OD Report
TotalSeconds NoteProperty System.String TotalSeconds=25
So the property does exist. Any idea what is going on? If I just type $AllContents, I get a list with the property also.
The hasOwnProperty() method will check if an object contains a direct property and will return true or false if it exists or not. The hasOwnProperty() method will only return true for direct properties and not inherited properties from the prototype chain.
If the property does not exist on the object, it will return the string undefined.
JavaScript provides you with three common ways to check if a property exists in an object: Use the hasOwnProperty() method. Use the in operator. Compare property with undefined .
In a JavaScript program, the correct way to check if an object property is undefined is to use the typeof operator. If the value is not defined, typeof returns the 'undefined' string.
What is your value for Set-StrictMode
can you test to remove strict mode before your code?
Set-StrictMode -Off
What are the results for :
Get-Member -InputObject $AllContents
Get-Member -InputObject $AllContents[0].RptFile
Try first
$AllContents[0].RptFile = '<value>'
if not something like this should help:
[Your.Interface.Implemented.Explicitly].GetProperty("RptFile").SetValue($AllContents[0], '<value>',$null)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With