Используйте Measure-Command, чтобы узнать время HTTP-запроса, но как получить среднее, минимальное и максимальное значения? - PullRequest
0 голосов
/ 08 ноября 2018

У меня есть скрипт, который запрашивает что-то в Sharpeoint, затем с каждым идентификатором документа он выполняет веб-сервис, я знаком с командлетом measure-command и работает довольно хорошо.

Однако я хотел бы изменить приведенный ниже скрипт, чтобы получить минимальное, максимальное и среднее время, необходимое для запроса

Код правильно показывает мне общее время выполнения всего сценария, но я хочу знать общее, среднее, минимальное и максимальное время выполнения блока TRY, а также

Я пытался поместить команду измерения внутри, но она запрашивает выражение, поэтому, по-видимому, две команды измерения, одна вложенная за другой, невозможна

 function Failure {
    $global:helpme = $body
    $global:helpmoref = $moref
    $global:result = $_.Exception.Response.GetResponseStream()
    $global:reader = New-Object System.IO.StreamReader($global:result)
    $global:responseBody = $global:reader.ReadToEnd();
    Write-Host -BackgroundColor:Black -ForegroundColor:Red "Status: A system exception was caught."
    Write-Host -BackgroundColor:Black -ForegroundColor:Red $global:responsebody
    Write-Host -BackgroundColor:Black -ForegroundColor:Red "The request body has been saved to `$global:helpme"
    break
}

 Measure-command {  
    If ((Get-PSSnapIn -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )  
    { Add-PSSnapIn -Name Microsoft.SharePoint.PowerShell } 

    $StartDate=(GET-DATE)
    $CutOffDate=(Get-date).AddDays(-540)
    $SPAssignment = Start-SPAssignment
    $SPWeb = Get-SPWeb https://oursite/sites/billing -AssignmentCollection $spAssignment
    # Next step is to get the list:
    $SPList = $SPWeb.Lists["Bill Cycles"]
     $spqQuery = New-Object Microsoft.SharePoint.SPQuery 
            $spqQuery.Query =  
                "   <Where> 
                    <And>
                        <Eq> 
                            <FieldRef Name='Bill_x0020_Preparation_x0020_Status' /> 
                            <Value Type='Text'>COMPLETED</Value> 
                        </Eq> 
                        <Leq>
                            <FieldRef Name='Bill_x0020_to_x0020_date' />
                            <Value Type='DateTime'>
                                <Today OffsetDays='540' />
                            </Value>
                        </Leq>
                    </And>
                </Where>" 
    $spqQuery.ViewFields = "<FieldRef Name='Bill_x0020_Preparation_x0020_Status' /><FieldRef Name='Title' /><FieldRef Name='Bill_x0020_to_x0020_date' /><FieldRef Name='ContentType'/><FieldRef Name='ID'/>" 
    $spqQuery.ViewFieldsOnly = $true 
    $splListItems = $SPList.GetItems($spqQuery) 
    $iNumber=1 
    $iNumberOfContentTypes=1 
    $iNumberOfBillCyclesArchived=0 
    $iNumberOfBillCyclesArchivedFailed=0 
    $cred = Get-Credential 
    foreach  ($splListItem in ($splListItems | Select-Object -First 10) )
    {
        $iNumber+=1 
        if( $splListItem["ContentType"] -eq "Bill Cycle"){           

           try {                
                    #Start-Sleep -s 65
                    $Url = "https://oursite/sites/billing/_vti_bin/DMS/DMSWebService.svc/Billing/ArchiveBillCycle/"+$splListItem["ID"]
                    #Write-Host $Url 
                    #https://oursite/sites/billing/_vti_bin/DMS/DMSWebService.svc/Billing/ArchiveBillCycle/145771
                    $r = Invoke-WebRequest -Credential $cred -Uri $Url   -TimeoutSec 180 -ErrorAction:Stop
                    #Write-Host $r.Content.ToString()
                    if($r.Content -like '*<RequestSucceeded>false</RequestSucceeded>*')
                    {
                        write-host "Archiving Failed, File # $iNumber - Bill Cycle Id:" $splListItem["ID"], "Title:" $splListItem["Title"] , "ContentType:" $splListItem["ContentType"] ,  "Status:" $splListItem["Bill_x0020_Preparation_x0020_Status"] , "Billtodate:" $splListItem["Bill_x0020_to_x0020_date"] -ForegroundColor Red 
                        $iNumberOfBillCyclesArchivedFailed+=1
                    }
                    elseif($r.Content -like '*<RequestSucceeded>true</RequestSucceeded>*')
                    {
                        write-host "Archived, File # $iNumber - Bill Cycle Id:" $splListItem["ID"], "Title:" $splListItem["Title"] , "ContentType:" $splListItem["ContentType"] ,  "Status:" $splListItem["Bill_x0020_Preparation_x0020_Status"] , "Billtodate:" $splListItem["Bill_x0020_to_x0020_date"] -ForegroundColor Green 
                        $iNumberOfBillCyclesArchived+=1
                    }
                    else{
                        write-host "Archived, File # $iNumber - Bill Cycle Id:" $splListItem["ID"], "Title:" $splListItem["Title"] , "ContentType:" $splListItem["ContentType"] ,  "Status:" $splListItem["Bill_x0020_Preparation_x0020_Status"] , "Billtodate:" $splListItem["Bill_x0020_to_x0020_date"] -ForegroundColor Green 
                        $iNumberOfBillCyclesArchived+=1
                    }   
           } 
           catch {
                $iNumberOfBillCyclesArchivedFailed+=1
                write-host "Archiving Failed, File # $iNumber - Bill Cycle Id:" $splListItem["ID"], "Title:" $splListItem["Title"] , "ContentType:" $splListItem["ContentType"] ,  "Status:" $splListItem["Bill_x0020_Preparation_x0020_Status"] , "Billtodate:" $splListItem["Bill_x0020_to_x0020_date"] -ForegroundColor Red 
                Failure
           }

           $iNumberOfContentTypes+=1
        }              
    } 

    Write-Host "Number of items in the query: "  $iNumber
    Write-Host "Number of content types in the query: "  $iNumberOfContentTypes
    Write-Host "Number of bill cycles archived: "  $iNumberOfBillCyclesArchived
    Write-Host "Number of bill cycles archived failed: "  $iNumberOfBillCyclesArchivedFailed


}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...