# PowerShell Protect

## Display Log Messages in PowerShell Universal <a href="#display-log-messages-in-powershell-universal" id="display-log-messages-in-powershell-universal"></a>

This example configures PowerShell Protect to send log messages to a PowerShell Universal instance. It sends HTTP POST requests to the configured server.

### PowerShell Protect Configuration <a href="#powershell-protect-configuration" id="powershell-protect-configuration"></a>

This configuration checks to see if the user has included the string `\\corp\human-resources` anywhere in their script. If they do, it sends an HTTP POST to the URL `http://localhost:8080/protect`

The body of the HTTP request will contain the computer name and user name separated by a comma.

```
$Condition = New-PSPCondition -Property "script" -Contains -Value "\\corp\human-resources"
$Block = New-PSPAction -Http -Address "http://localhost:8080/protect" -Format "{computerName},{userName}" -Name 'Universal'
$Rule = New-PSPRule -Action $Block -Condition $Condition -Name "HR Share"
$Config = New-PSPConfiguration -Rule $Rule -Action $Block -License "<License></License>"

Set-PSPConfiguration -Configuration $Config -FileSystem
```

### PowerShell Universal Configuration <a href="#powershell-universal-configuration" id="powershell-universal-configuration"></a>

This PSU configuration defines an endpoint to accept the POST data from PowerShell Protect. It then saves the data to a file. It also defines a dashboard that will read the data and display it in a table. This assumes that you have installed the PowerShell Universal module and server.

```
Start-PSUServer -Port 8080 -Configuration {    
    New-PSUEndpoint -Url "/protect" -Method POST -Endpoint {
       $Data = "$Env:Temp\data.csv"        
       if (-not (Test-Path $Data))        
       {            
          "computer,user" | Out-File $Data        
       }        
       $Body | Out-File $Data    
    }​    
    New-PSUDashboard -Name "Protect" -Content {        
       New-UDDashboard -Title 'Protect' -Content {            
          $Data = Import-Csv -Path "$Env:Temp\data.csv"            
          New-UDTable -Data $Data        
       }    
    }
 }
```

Here is an example of the output for the dashboard.![](https://gblobscdn.gitbook.com/assets%2F-MEuLp20fz-Rt56KSsmu%2F-MOEavYKAK53ueHeiHCF%2F-MOEilnbwR9aCdmFg5uc%2Fimage.png?alt=media\&token=005e9fcb-1e9c-4bc3-bc46-2cfd5072bf1d)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.powershelluniversal.com/v1/examples/powershell-protect.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
