Hi Guys,
Have a strange problem that’s got me scratching my head (I’ll be going bald soon at this rate)
For the experts here this will be very simple. Trying to pass an array into a function. Here is the mechanism of parsing:
$LogData=
@{
DelegateName=$DelegateName
DelegateAccess=$DelegateAccess
Mailbox=$DisplayName
FriendlyText="Delegate Found"
Code="DELEGATES"
} #END Splat
#*** Send to Log Function ***
Write-Log $LogData
Here is the function:
Function Write-Log ([Array]$LogData,[Array]$InvocationError) {
If ($LogData.Code -eq "SUCCESS") {
Write-Host "[SUCCESS]`t $($LogData.FriendlyText) `t ObjectGuid $($LogData.GUID) `t DisplayName $($LogData.DisplayName)" -ForegroundColor Green
"[SUCCESS]`t $($LogData.FriendlyText) `t $($LogData.GUID) `t DisplayName $($LogData.DisplayName)`n"| Out-File $Log -Append }
ElseIf ($LogData.Code -eq "DELEGATES") {
Write-Host "[DELEGATES]`t $($LogData.DelegateName) has access to Mailbox $($LogData.Mailbox) with access level $($LogData.DelegateAccess)" -ForegroundColor Yellow
"[DELEGATES]`t $($LogData.FriendlyText)`t`t`t $($LogData.DelegateName) has access to Mailbox $($LogData.Mailbox) with access level $($LogData.DelegateAccess)`n"| Out-File $Log -Append }
ElseIf ($LogData.Code -eq "ERROR") {
Write-Host "[ERROR]`t`t TRY Index: $($LogData.TryIndex) Name: $($LogData.Name) TargetName: $($LogData.TargetName) Exception: $($LogData.Exception)" -BackgroundColor Red
"[ERROR]`t`t TRY Index: $($LogData.TryIndex)`t`t $($LogData.GUID) Name: $($LogData.Name)`t TargetName: $($LogData.TargetName) Exception: $($LogData.Exception)" | Out-File $Log -Append
"[ERROR]`t`t TRY Index: $($LogData.TryIndex)`t`t $($LogData.GUID) Name: $($LogData.Name) DN: $($LogData.DN)`t TargetName: $($LogData.TargetName) Exception: $($LogData.Exception) Error0: $($LogData.Error0) Error1: $($LogData.Error1) Error2: $($LogData.Error2)" | Out-File $ErrorLog -Append
$invocation | Out-File $ErrorLog -Append }
}
Debugging reveals that before the parsing the $logData is populated, but when it arrives at the Write-Log function its empty. I did a $logData.Get-Type() and its a hashtable type system.object as expected before being parsed.
Here is its contents:
Name Value ---- ----- TargetName ToMB Error2 Exception calling ".ctor" with "2" argument(s): "Cannot process argument because the value of argument "password" is null. Change the value of argument "password" to a non-null value." Exception Method invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named 'ToMB'. Error1 The property cannot be processed because the property "DisplayName" already exists. GUID b4f3eca8-2b53-4feb-9759-c19358d925b5 DN CN=Dawn,OU=Users,OU=CompanyName,DC=corp,DC=expopssandbox3,DC=co,DC=uk Name Dawn TryIndex 002 FN-PM Code Error Error0 Method invocation failed because [Deserialized.Microsoft.Exchange.Data.ByteQuantifiedSize] does not contain a method named 'ToMB'.
Here is its type:
IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True Hashtable System.Object
THanks
Stuart