Examples/GM/run.ps1
# run.ps1 auto-generated by EasyAzureFunction module, https://github.com/iricigor/EasyAzureFunction, iricigor@gmail.com 'run.ps1 start' # POST method: $req $requestContent = Get-Content $req -Raw try { $requestBody = $requestContent | ConvertFrom-Json $Failed = $false "Params (JSON): $($requestBody.PSObject.Properties.Name -join `",`")" $EzInvokeCommand = $requestBody.EzInvokeCommand $EzName = $requestBody.EzName $EzFullyQualifiedName = $requestBody.EzFullyQualifiedName $EzAll = $requestBody.EzAll $EzListAvailable = $requestBody.EzListAvailable $EzPSEdition = $requestBody.EzPSEdition $EzRefresh = $requestBody.EzRefresh $EzPSSession = $requestBody.EzPSSession $EzCimSession = $requestBody.EzCimSession $EzCimResourceUri = $requestBody.EzCimResourceUri $EzCimNamespace = $requestBody.EzCimNamespace } catch {$Failed = $true} if ($Failed) { "Params (URLEncoded): $requestContent" $requestContent -split '&' | % { $v = $_ -split '=' if ($v[1]) {Set-Variable -Name $v[0] -Value $v[1]} } } # prepare output, either default web-page or invoke command if (!$EzInvokeCommand) { 'show default web page' cd $EXECUTION_CONTEXT_FUNCTIONDIRECTORY $Output = Get-Content .\index.html -Raw } else { 'invoke command' try { $ParamsHash = @{} if ($EzName) {$ParamsHash.Add('Name',@($EzName -replace '%2C',',' -split ','))} if ($EzFullyQualifiedName) {$ParamsHash.Add('FullyQualifiedName',@($EzFullyQualifiedName -replace '%2C',',' -split ','))} if ($EzAll) {$ParamsHash.Add('All',$True)} if ($EzListAvailable) {$ParamsHash.Add('ListAvailable',$True)} if ($EzPSEdition) {$ParamsHash.Add('PSEdition',$EzPSEdition)} if ($EzRefresh) {$ParamsHash.Add('Refresh',$True)} if ($EzPSSession) {$ParamsHash.Add('PSSession',$EzPSSession)} if ($EzCimSession) {$ParamsHash.Add('CimSession',$EzCimSession)} if ($EzCimResourceUri) {$ParamsHash.Add('CimResourceUri',$EzCimResourceUri)} if ($EzCimNamespace) {$ParamsHash.Add('CimNamespace',$EzCimNamespace)} "Params: $($ParamsHash.Keys -join `",`")" $Output = Get-Module @ParamsHash | Out-String if ($Output) {$Color = 'white'} else {$Color = 'gray'; $Output = 'Command run successfully, but it returned no output'} } catch { $Output = $_ $Color = 'red' } $Head = "<head><style>body {background-color: #012456; color: $Color;}</style><title>EasyAzureFunction - Get-Module running example</title></head>" $Back = '<p><a href="javascript:history.back()" style="color:yellow;">Go Back</a></p>' $Output = $Head + '<pre>' + $Output + $Back + '</pre>' $Output = $Output -replace "`n",'</br>' } # parse and send back output $Output2 = [PSCustomObject]@{Status = 200; Body = ''; Headers = @{}} $Output2.Headers.Add('content-type','text/html') $Output2.Body = $Output -replace '"',"'" Out-File -Encoding utf8 -FilePath $res -inputObject ($Output2 | ConvertTo-JSON) |