Third Real Test Post

Test

Preface

While working on my PoShDynDnsApi module, I came across an issue with with a function I had predominantly borrowed from a TechNet blog post from Jamie Nelson. Specifically, in my function Update-DynDnsRecord that called the Compare-ObjectProperties function, when I used the -WhatIf parameter, I unexpectedly received the following:

What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: ipaddress Address {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Name {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: int TTL {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Type {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Zone {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: ipaddress Address {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Name {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: int TTL {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Type {get;set;}".
What if: Performing the operation "Retrieve the value for property 'Name'" on target "InputObject: string Zone {get;set;}".

The Compare-ObjectProperties seemed to be throwing these additional What If statements. I saw where the ForEach-Object alias of % was used a few times and determined that these two lines were the cause.

$objprops = $ReferenceObject | Get-Member -MemberType Property,NoteProperty | % Name
$objprops += $DifferenceObject | Get-Member -MemberType Property,NoteProperty | % Name

Script Blocks and -WhatIf

I had hoped that I could provide -Begin, -Process, and -End parameters along with -WhatIf as illustrated in the following code:

PS C:\> 'testing1','testing2' |  ForEach-Object -Begin {
    Write-Output 'Starting'
    } -Process {
        Write-Output "Processing $_"
    } -End { Write-Output 'Ending'
    } -WhatIf

Conclusion

Note: I never considered forgoing advanced functions, just that the cmdlet could be an ad hoc supplement.

2020

Back to top ↑

2019

Back to top ↑

2018

Back to top ↑