29 lines
936 B
PowerShell
29 lines
936 B
PowerShell
|
function Copy-ObjectProperties {
|
||
|
<#
|
||
|
.SYNOPSIS
|
||
|
Copies properties from one object to another
|
||
|
#>
|
||
|
param(
|
||
|
[Parameter(Position = 0, Mandatory = $true)]
|
||
|
[Object]$SourceObject,
|
||
|
|
||
|
[Parameter(Position = 1, Mandatory = $true)]
|
||
|
[Object]$DestinationObject,
|
||
|
|
||
|
[Parameter(Position = 2, Mandatory = $false)]
|
||
|
[string[]]$PropertiesToSkip
|
||
|
)
|
||
|
|
||
|
foreach ($property in $SourceObject.PsObject.Properties) {
|
||
|
if (($PropertiesToSkip -notcontains $property.Name) -and
|
||
|
($null -ne $DestinationObject.PsObject.Properties.Match($property.Name)) -and
|
||
|
($DestinationObject.PsObject.Properties[$property.Name].TypeNameOfValue -eq $property.TypeNameOfValue) -and
|
||
|
($DestinationObject.PsObject.Properties[$property.Name].IsSettable)) {
|
||
|
$DestinationObject.PsObject.Properties[$property.Name].Value = $property.Value
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$DestinationObject
|
||
|
}
|
||
|
|