+2 votes

Most of my PowerShell code is written in VS Code and then copied/pasted to the Adaxes script editor. However, if you use $Context in your scripts, you can't execute them from VS Code (or ISE, Terminal, etc.).

I was recently working on a script that used the Adaxes PowerShell module and I was only using $Context for logging. I realized that I could emulate $Context.LogMessage() and $Context.LogExcecption() easily, and debug right in VS Code. Obviously, this won't work if you're using more advanced features of $Context, but for basic logging it works great.

PS...I had made an enhancement request a while back for an Adaxes plugin for VS Code. Please upvote that post! https://www.adaxes.com/questions/13285/add-visual-studio-code-support


# define the message type to avoid any typos when calling LogMessage()
enum MessageType {
    Information = 0
    Warning = 1
    Error = 2

class Context {    
    [string]LogMessage ([string]$message, [MessageType]$type) {        
        return "[$type] $message"
    [string]LogException ([string]$message) {
        return "[Error] $message"

$Context = [Context]::new()
$Context.LogMessage("foo", "information")


[Information] foo
by (180 points)

1 Answer

0 votes
by (267k points)


Thank you for sharing the approach. We also added a +1 on your behalf to the suggestion.


Really nice and helpful. Saves me now a lot of time in future :D

I always did a find/replace of this command with Write-Output ...

Related questions

0 votes
1 answer

I am trying to send a $context.logmessage from a condition script in a Scheduled Task but I get nothing in the log. Is this not possible? Morten A. Steien

asked Jul 20, 2020 by Morten A. Steien (300 points)
0 votes
1 answer

Hi All, I am currently using the 30 day free trial of Adaxes and seeing if we can use it to achieve our method of user provisioning. I am looking into server-side ... variable value within an SQL query Can this be achieved? Any help is much appreciated, Thanks

asked Feb 1 by Lewis (40 points)
0 votes
1 answer

Receive "Index operation failed; the array index evaluated to null. Stack trace: at <ScriptBlock>, <No file>: line 104>" and "Index operation failed; the ... $GroupName, $GroupDN." } } #foreach write-output "" Write-Output "" Stop-Transcript

asked Apr 14, 2022 by jbahou (20 points)
0 votes
1 answer

Hello I'm trying to run a custom PowerShell script to request a Workspace ONE Access Sync when I change something in our users or groups. Here is the script: $ClientId = "api ... of having to create 6 independent rules with each of them a copy of the script)?

asked Sep 25, 2021 by ygini (240 points)
0 votes
1 answer

Hello How can I use a script to search for "123France - Create" in the business rules and replace the "123France - Create" with "France - Update"? This would be an ... done throughout the CN=Business Rules. It will always be searched for "123France - Create".

asked Aug 25, 2023 by DRiVSSi (200 points)
3,293 questions
2,991 answers
544,194 users