commit 49e0ffea6b0c14dc0289336a6b905b3ffdf53888 Author: Torste Brendgen Date: Mon Aug 18 21:28:12 2025 +0200 Initial commit diff --git a/Microsoft.SelfService.Portal.PowerShell.Core.psd1 b/Microsoft.SelfService.Portal.PowerShell.Core.psd1 new file mode 100644 index 0000000..8711ed8 --- /dev/null +++ b/Microsoft.SelfService.Portal.PowerShell.Core.psd1 @@ -0,0 +1,11 @@ +@{ + ModuleVersion = '1.0.0' + GUID = '57f3262e-9730-47dc-b9ae-314799bef88e' + Author = 'Torsten Brendgen' + Description = 'Microsoft SelfService Portal Domain PowerShell Functions' + RootModule = 'Microsoft.SelfService.Portal.PowerShell.Core.psm1' + FunctionsToExport = '*' + CmdletsToExport = @() + VariablesToExport = @() + AliasesToExport = @() +} \ No newline at end of file diff --git a/Microsoft.SelfService.Portal.PowerShell.Core.psm1 b/Microsoft.SelfService.Portal.PowerShell.Core.psm1 new file mode 100644 index 0000000..5c3b34f --- /dev/null +++ b/Microsoft.SelfService.Portal.PowerShell.Core.psm1 @@ -0,0 +1,53 @@ +function Invoke-SSPRequest { + Param( + [Parameter(Mandatory=$false)] + [ValidateSet('Get','Post','Put','Delete')] + [System.String] $Method = 'Get', + [Parameter(Mandatory=$true)] + [System.String] $Endpoint, + [Parameter(Mandatory=$false)] + [System.String] $Query, + [Parameter(Mandatory=$false)] + [System.String] $Body + ) + + if($Query){ + $Uri = $("https://localhost:7260/api/"+$Endpoint+"/"+$Query) + }else{ + $Uri = $("https://localhost:7260/api/"+$Endpoint) + } + + switch($Method){ + {($_ -eq "Get") -or ($_ -eq "Delete")} { + $Parameter = @{} + $Parameter.Add("Method",$Method) + $Parameter.Add("Uri", $Uri) + $Parameter.Add("UseDefaultCredentials",$true) + $Parameter.Add("ContentType","application/json") + } + + {($_ -eq "Post") -or ($_ -eq "Put")} { + $Parameter = @{} + $Parameter.Add("Method",$Method) + $Parameter.Add("Uri", $Uri) + $Parameter.Add("Body", $Body) + $Parameter.Add("UseDefaultCredentials",$true) + $Parameter.Add("ContentType","application/json") + } + } + + try { + # Versuch, die Anfrage auszuführen + $Response = Invoke-RestMethod @Parameter + return $Response + } catch [System.Net.WebException] { + # Fehler abfangen und Antwort auswerten + $ErrorResponse = $_.Exception.Response + if ($ErrorResponse -ne $null) { + $Reader = New-Object System.IO.StreamReader($ErrorResponse.GetResponseStream()) + return $($Reader.ReadToEnd() | ConvertFrom-Json) + } else { + Write-Host "Kein Antwortkörper verfügbar." + } + } +}