param( [Parameter(Mandatory)] $oldObject, [Parameter(Mandatory)] $newObject ) $result = $oldObject.PSObject.Properties.Name | ForEach-Object { $prop = $_ $oldValue = $oldObject.$prop $newValue = $newObject.$prop # null または単純値のみ対象 # IsPrimitive は Boolean、Int32、Int64、Double など $isSimple = $null -eq $oldValue -or $oldValue.GetType().IsPrimitive -or $oldValue -is [string] -or $oldValue -is [decimal] -or $oldValue -is [datetime] -or $oldValue -is [timespan] -or $oldValue -is [guid] -or $oldValue.GetType().IsEnum if ($isSimple) { $oldText = if ($null -eq $oldValue) { $null } else { $oldValue.ToString() } $newText = if ($null -eq $newValue) { $null } else { $newValue.ToString() } if ($oldText -ne $newText) { [pscustomobject]@{ Property = $prop OldValue = $oldText NewValue = $newText } } return } # ---------------------------------------- # Get-VMHost の例外 # コレクション型プロパティ # ---------------------------------------- switch ($prop) { 'InternalNetworkAdapters' { $oldText = @($oldValue).Count $newText = @($newValue).Count } 'ExternalNetworkAdapters' { $oldText = @($oldValue).Count $newText = @($newValue).Count } 'SupportedVmVersions' { $oldText = ( @($oldValue) | ForEach-Object { $_.ToString() } | Sort-Object ) -join ',' $newText = ( @($newValue) | ForEach-Object { $_.ToString() } | Sort-Object ) -join ',' } 'SecureBootTemplates' { $oldText = ( @($oldValue) | ForEach-Object { $_.Id.ToString() } | Sort-Object ) -join ',' $newText = ( @($newValue) | ForEach-Object { $_.Id.ToString() } | Sort-Object ) -join ',' } 'GuestIsolationTypes' { $oldText = ( @($oldValue) | ForEach-Object { $_.ToString() } | Sort-Object ) -join ',' $newText = ( @($newValue) | ForEach-Object { $_.ToString() } | Sort-Object ) -join ',' } default { # HostNumaStatus / NumaStatus は除外 return } } if ($oldText -ne $newText) { [pscustomobject]@{ Property = $prop OldValue = $oldText NewValue = $newText } } # ---------------------------------------- # Get-VMHost の例外終わり # ---------------------------------------- } $result