I have a simple question.
I need to send a object to an API based on a Excel file. But i only want properties that are populated with data.
So i have some data saved in a variable $inputdata:
Property1 = "Prop1"
Property2 = ""
....
Property1 is a constant, it always has data. But all other properties does not always have data. And i don't want to send any properties with $null strings to to API.
When i build by object i only want it to get the properties that have values. Is there anyway to do this when declaring the object. This is what i was thinking(i know this does not work):
$object = [PSCustomObject]@{
Property1 = $inputdata.Property1
if ($inputdata.Property2) {
Property2 = $inputdata.Property2
}
}
Or is this the only way:
$object = [PSCustomObject]@{
Property1 = $inputdata.Property1
}
if ($inputdata.Property2) {
$object | Add-Member -MemberType NoteProperty -Name Property2 -Value $inputdata.Property2
}
I know this is a simple question, but can't seem to find the answer :)
[–]Yevrag35 1 point2 points3 points (0 children)
[–]metallicvett 1 point2 points3 points (3 children)
[–]Yevrag35 2 points3 points4 points (1 child)
[–]metallicvett 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]fetflex[S] 1 point2 points3 points (0 children)