Запуск сценария powershell через веб-интерфейс API, требуется ответ этого API-файла в виде файла Excel, который генерируется сценарием ps1. - PullRequest
0 голосов
/ 02 января 2019

Я создал веб-API, с помощью которого я выполняю сценарий PowerShell, который создает файл Excel с необходимыми данными (журнал аудита) в локальной системе ... Но я хочу получить файл Excel в ответ на этот API-интерфейс.Как мне этого добиться?

Код моего скрипта Powershell: -

# Create the session to Exchange Online
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -Uri https://outlook.office365.com/powershell-liveid/  -Credential $UserCredential -Authentication Basic -AllowRedirection

# Import the Exchange Online commands
Import-PSSession $Session
$csvFile = "C:\Reports\auditlog2.csv"
# Setup our start and end dates to pull back events
#$start = Get-Date
$end = Get-Date
$start = $end.AddDays(-1)
$i = 1;
$startTime = Get-Date
do
{
$AuditData = Search-UnifiedAuditLog -StartDate $start -EndDate $end -RecordType SharePointFileOperation -ResultSize 5000 -SessionCommand ReturnLargeSet -SessionId "ExtractLogs" -SiteIds siteid
$ConvertedOutput = $AuditData | Select-Object -ExpandProperty AuditData | ConvertFrom-Json
$ConvertedOutput | SELECT CreationTime,UserId,Operation,Workload,ObjectID,SiteUrl,SourceFileName,ClientIP,UserAgent | Export-csv $csvFile -NoTypeInformation -Append -Force 
Write-Host $i++ . $AuditData.Count
$i = $i + 1;
}
Until($AuditData.Count -eq 0)

Remove-PSSession $Session

Код моего Web Api: -

Runspace runspace = RunspaceFactory.CreateRunspace();
        runspace.Open();
        Pipeline pipeline = runspace.CreatePipeline();
        // Add your path or relative one
        pipeline.Commands.AddScript(@"C:\Reports\spauditapi-Modified\spauditapi-master\SPAuditApi\Shell_Script\ReportGenerationforPermission.ps1");
        //pipeline.Commands.AddScript(@"../Shell_Script/ReportGenerationforPermission.ps1");
        pipeline.Commands.Add("Out-String");

        //Collection <psobject/> results = pipeline.Invoke();
        var results = pipeline.Invoke();
        StringBuilder stringBuilder = new StringBuilder();
        foreach (PSObject obj in results)
        {
            stringBuilder.AppendLine(obj.ToString());
        }
        return stringBuilder.ToString();
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...