I temporarily removed logging.ps1 today and tested if I can see the actual logging targets in the meantime. And yes, they now show up cleanly on both hosts.
I noticed that for the LoggingTarget with -Type file a “RetentionPeriod: 30” is displayed.
Unfortunately, the documentation for the New-PSULoggingTarget function doesn’t give any details on how I can set this value (using Get-Help). On the Logging documentation page (Logging - PowerShell Universal), unfortunately, I don’t see any link to further instructions on how to use the function in more detail.
Question 1:
Is there a place I don’t know where I can get more info?
In the current state I get, even with yesterday’s suggestions, neither with -Scope user, system or without Scope anything is logged.
Question 2:
How can I reactivate that I get ALL logs that PowerShell Universal produces?
Basically I am trying to create an API endpoint, unfortunately I am getting an error code 400 via Invoke-RestMethod, but no logs at all.
Therefore, I simply do not know where my mistake lies. At the endpoint? In the call? Permissions? Error in the function of the PowerShell module?
Ideally I would like to have all the logs in one central place so I can check my verbose output (if any) - but as of yet I just haven’t received a single line as a log in the system.
Current API Endpoint setup:
- Self-created PowerShell module
- API Endpoint:
New-PSUEndpoint -Url "/dev/new/computer" -Description "Create a new server object in ActiveDirectory using JSON" -Method @('POST') -Endpoint {
param(
[Parameter(Mandatory)]$ComputerName,
[Parameter(Mandatory)]$BusinessUnit,
[Parameter(Mandatory)]$Application,
[Parameter(Mandatory)][ValidateSet("Windows", "Other")]$OperatingSystem,
[Parameter(Mandatory)]$FreeText,
[Parameter(Mandatory)][ValidateSet("Productive", "Test", "Development")]$Environment,
[Parameter(Mandatory)]$Owner1,
[Parameter(Mandatory)]$Owner2,
[Parameter(Mandatory)]$DepartmentNumber
)
Write-Verbose "-Application $BusinessUnit\$Application" -Verbose
Write-Verbose "-Owners $Owner1, $Owner2" -Verbose
Write-PSULog -Feature 'T1ComputerAPIEndpoint' -Message '-Application ' + $BusinessUnit + '\' + $Application
Write-PSULog -Feature 'T1ComputerAPIEndpoint' -Message '-Owners ' + $Owner1 + '\' + $Owner2
$newComputer = New-Computer -Application "$BusinessUnit\$Application" -Tier T1 -Name $ComputerName -Type Server -OperatingSystem $OperatingSystem -DepartmentNumber $DepartmentNumber -Freetext $FreeText -Environment $Environment -Owners "$Owner1, $Owner2"
if ($newComputer) {
return ($newComputer | ConvertTo-Json)
}
} -Environment "Windows PowerShell 5.1" -Tag @('post') -Documentation "DEV-EDKADRZS"
- API Endpoint calls a function of the self-created PowerShell module and returns the result as JSON (if available)
- Call the API Endpoint with:
Invoke-RestMethod https://my.psu.host/dev/new/computer -Method POST -Body (@{Computername = "Test"; BusinessUnit = "ABC"; Application = "MyApplication"; OperatingSystem = "Other"; FreeText = "AnyString"; Environment = "Test"; Owner1 = "1234567"; Owner2 = "9876543"; DepartmentNumber = "101010"} | ConvertTo-Json) -ContentType 'application/json'
- Result without any further logs:
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:1 char:11
+ $result = Invoke-RestMethod https://my.psu.host/dev/new/computer ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Question 3:
As of now I strongly assume that my call with Invoke-RestMethod is faulty and therefore I don’t get a Write-Verbose or Write-PSULog. But it must be known to PowerShell Universal that an incorrect call has occurred and why it failed, right?