I am trying to save some date to a PSCustomObject in one function and pass that object to another function so I can access the objects properties and values. I am doing something incorrect as I can not access anything from the object in the second function. What am I doing wrong. I can access the objects properties and values if i don't pass it to another function. Here is an example of what i am trying to do (this is just the test to see how to do it, my actual code will manipulate the date stored in the object). Thanks for any help or insight you can provide.
Function test {
try{
$dateTimeInput = Read-Host -Prompt "Enter date (format 6/1/2025 3:15PM)"
$myObject = [PSCustomObject]@{
date1 = Get-Date $dateTimeInput
date2 = Get-Date $dateTimeInput -Format "MMddyyyy-HHmm"
}
} Catch{Write-host "no good"
test
}
return $myObject
}
Function test2 {
param(
$myObject
)
Write-Host "111111" $myObject.date1
Write-Host "222222" $myObject.date2
}
test
test2 $myObject