0

I would like to make a script that compares O365 tenant settings. Reading them is fine, now I would like to make some kind of difference object. A related question is here, but no answer. Powershell Compare-Object and getting the Differences into a File

I already have a json file from both tenants created like:

$srcTenant | Select-Object -Property * | ConvertTo-Json | Out-File "$targetfolder\$targetfile"

Now, I would like a file that only contains the properties that are collected with the script below:

I am so far:

$properties = ($srcTenant | Get-Member -MemberType Property | Select-Object -ExpandProperty Name)
$selectedproperties = @{}
$i = 0
foreach ($property in $properties) {
  if (Compare-Object $srcTenant $trgTenant -Property "$property") {
  $selectedproperties.Add($i, "$property")
  $i++
  }
}

The $selectedproperties variable contains 9 properties and I would like to export only this 9 in the same format as the other two.

Name Value
---- -----
8 StorageQuotaAllocated
7 StorageQuota
6 ResourceQuotaAllocated
5 ResourceQuota
4 OwnerAnonymousNotification
3 OneDriveStorageQuota
2 DefaultLinkPermission
1 ConditionalAccessPolicy
0 AllowDownloadingNonWebViewableFiles

So, I am looking for something like:

$srcTenant | Select-Object -Property (that 9 property above) | ConvertTo-Json | Out-File "$targetfolder\$targetfile

Other options achieving the same result are welcome too :)

vilmarci
  • 451
  • 10
  • 31

1 Answers1

0

Select-Object -Property can take an array of property names.

see the first example here

mhhollomon
  • 965
  • 7
  • 15
  • How would I pass the properties as array? I am not really familiar with this area of PS. – vilmarci Dec 06 '18 at 21:41
  • @vilmarci - something like `select-object -Property $selectedproperties.values` would work for this situation. [This page](https://kevinmarquette.github.io/2018-10-15-Powershell-arrays-Everything-you-wanted-to-know) is a good intro to powershell arrays. – mhhollomon Dec 06 '18 at 22:35
  • Thanks, `$selectedproperties.values` didn't work, but the solution was using an array instead of the hashtable. I switched to that and now it works :) – vilmarci Dec 07 '18 at 07:42