.net
3 TopicsHow to access or set .NET class property from PowerShell
I have a .NET library and I want to call it's function/constructor from PowerShell. In this case expecting it to print a HyperLink on console. Here is the schema for the Log class In C#, it is called as Log.Trace(new CommentTrace("Comment message") { XmlAnnotation="<SupportingInfo><Item /></SupportingInfo>" }); Log.Trace(new CommentTrace("Error message") { XmlAnnotation = "<SupportingInfo>" + "<Item Name=\"Test Wiki\" Value=\"htpps://xyz.com\" Type =\"url\" />" + "</SupportingInfo>" }); How do I call it in powershell? Trying [LOG]::Trace((New-Object CommentTrace 'URL Argument' -Property @{ XmlAnnotation="<SupportingInfo><Item Name='URL Hyperlink' Value='$URLValue' Type ='url'></item></SupportingInfo>"} )) [LOG]::Trace((New-Object CommentTrace 'URL Argument' -Property @{ XmlAnnotation="<SupportingInfo><Item Name='URL Hyperlink' Value='$URLValue' Type ='url'></item></SupportingInfo>"} )) However it ends up ignoring the XMLAnnotation property entirely. Expected: to consider the XMLAnnotation passed and print the hyperlink How to achieve get this working in powershell. And how to learn converting .NET OOOPs code in powershell1.9KViews0likes1Comment.Net mail message, PowerShell and Microsoft Purview Infrmation Protection
I have a PowerShell script that using the .net mail message to send emails. We want to restrict some of those emails to a certain sensitivity (we call it classification) and restrict it to only internal users (which this label does when sending via Outlook). I have looked at a number of ways to do this but haven't come up with anything that works. Here are the issues: The smtp server is NOT in Office 365. The PowerShell window is opened as an admin account so using an Outlook interface might not work. Currently, I have it set to send remotly (A session is created with the server that is whitelisted and it actually sends the message). Any information would be of great assistance.100Views0likes2CommentsArray and array member methods
The following PowerShell code: class MyClass { } class MyClass1 : MyClass { [void] OutMsg([string] $Str) { Write-Host -Object "MyClass1: $Str" } } class MyClass2 : MyClass { [void] OutMsg([string] $Str) { Write-Host -Object "MyClass2: $Str" } } [MyClass[]] $ClassArray = @([MyClass1]::new(), [MyClass2]::new()) $ClassArray.OutMsg('TestString') outputs: MyClass1: TestString MyClass2: TestString A Get-Member -InputObject $ClassArray shows me that the array object itself has no OutMsg method. Why can I successfully call $ClassArray.OutMsg('TestString') though (looks like this calls the OutMsg method of each array member in turn)?92Views0likes3Comments