From c754b674e5b1275fd7ecac1f03bc93b06b95d664 Mon Sep 17 00:00:00 2001 From: kenichiro nakamura Date: Sat, 26 Dec 2015 00:10:35 +0900 Subject: [PATCH] fixed Test-CrmViewPerformance --- .../Microsoft.Xrm.Data.PowerShell.psm1 | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1 b/Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1 index c88508e..5cd622e 100644 --- a/Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1 +++ b/Microsoft.Xrm.Data.PowerShell/Microsoft.Xrm.Data.PowerShell.psm1 @@ -7753,7 +7753,6 @@ function Test-CrmViewPerformance{ $conn = VerifyCrmConnectionParam $conn; - # Define query related values if($IsUserView) { $logicalName = "userquery" @@ -7774,7 +7773,7 @@ function Test-CrmViewPerformance{ elseif($viewName -ne "") { $views = Get-CrmRecords -conn $conn -EntityLogicalName $logicalName -FilterAttribute name -FilterOperator eq -FilterValue $viewName -Fields $fields - if($views.CrmRecords.Count -eq 0) + if($views.CrmRecords.Count -eq 0) { return } @@ -7787,42 +7786,42 @@ function Test-CrmViewPerformance{ # if the view has ownerid, then its User Defined View if($View.ownerid -ne $null) { - if($RunAs -ne $null) + if($RunAsViewOwner) { - Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs + Set-CrmConnectionCallerId -conn $conn -CallerId $view.ownerid_property.Value.Id + } + elseif($RunAs -ne $null) + { + Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs } else { Set-CrmConnectionCallerId -conn $conn -CallerId (Get-MyCrmUserId -conn $conn) } - # Get all records by using viewname + # Get all records by using Fetch Test-XrmTimerStart $records = Get-CrmRecordsByFetch -conn $conn -Fetch $View.fetchxml -AllRows -ErrorAction SilentlyContinue -WarningAction SilentlyContinue $perf = Test-XrmTimerStop - $owner = "System" + $owner = $View.ownerid $totalCount = $records.Count } else - { - if($RunAsViewOwner) - { - Set-CrmConnectionCallerId -conn $conn -CallerId $view.ownerid_property.Value.Id - } - elseif($RunAs -ne $null) + { + if($RunAs -ne $null) { - Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs + Set-CrmConnectionCallerId -conn $conn -CallerId $RunAs } else { Set-CrmConnectionCallerId -conn $conn -CallerId (Get-MyCrmUserId -conn $conn) } - # Get all records by using viewname + # Get all records by using Fetch Test-XrmTimerStart $records = Get-CrmRecordsByFetch -conn $conn -Fetch $View.fetchxml -AllRows -ErrorAction SilentlyContinue -WarningAction SilentlyContinue $perf = Test-XrmTimerStop - $owner = $View.ownerid + $owner = "System" $totalCount = $records.Count } @@ -7830,8 +7829,8 @@ function Test-CrmViewPerformance{ $psobj = New-Object -TypeName System.Management.Automation.PSObject Add-Member -InputObject $psobj -MemberType NoteProperty -Name "ViewName" -Value $View.name - Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Entity" -Value $View.returnedtypecode Add-Member -InputObject $psobj -MemberType NoteProperty -Name "FetchXml" -Value $View.fetchxml + Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Entity" -Value $View.returnedtypecode Add-Member -InputObject $psobj -MemberType NoteProperty -Name "Columns" -Value ([xml]$view.layoutxml).grid.row.cell.Count Add-Member -InputObject $psobj -MemberType NoteProperty -Name "LayoutXml" -Value $view.layoutxml Add-Member -InputObject $psobj -MemberType NoteProperty -Name "TotalRecords" -Value $totalCount