I have a problem with my code. I need to grab user details using PowerShell and then export them to JSON so I can use them in Python. Everything works great, except for exporting one variable.
That's the code I use:
$manager | Add-Member -NotePropertyName "CreateOnIDs" -NotePropertyValue $managerSecondaryID
$newAccountData += New-Object PSObject -Property @{employee=$employee; secondaryID=$testedSecondaryID[1]; employeeType=$secondaryID_EmployeeType; path=$path; manager=$manager}
Output:
{
"path": "OU=OU,DC=domain,DC=domain,DC=net",
"secondaryID": "XXXXXXY1",
"manager": [
{
"ID": "xxxxxxx",
"FirstName": "FakeName",
"LastName": "FakeLastName",
"DisplayName": "FakeDisplayName",
"Domain": "FakeDomain",
"CreateOnIDs": "xxxxxxz xxxxxxy xxxxxxq"
}
],
"employee": [
{
"ID": "xxxxxx0",
"FirstName": "FakeName",
"LastName": "FakeLastName",
"EmailAddress": "Fake.Email@fake.com",
"Title": "FakeTitle",
"Department": "FakeDepartment",
"Company": "FakeCompany",
"Country": "Country",
"EmployeeType": "EMP",
"Manager": "CN=xxxxxxx,OU=Users,OU=IT,DC=domain,DC=domain,DC=net",
"Domain": "domain.domain.net",
"CreateOn": "domain.domain.net",
"AccountType": "SelectedAccountType"
}
],
"employeeType": "EmployeeType"
}
So I'm getting the output I'd like to have but the problem is with manager['CreateOnID']. I need to have it in following format:
"CreateOnIDs": [
"xxxxxxz",
"xxxxxxy",
"xxxxxxq"
]
What's weird is that when I use ConverTo-Json on the $manager variable only then I'm getting the correct result. My guess would be that something is wrong while I create $newAccountData, but I'm unable to find a solution.
$manager.CreateOnIDs is
IsPublic isSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array