Skip to main content

All Questions

Tagged with
0 votes
4 answers
74 views

Create distinction between Visual Studio Instances (e.g. 2022 vs 2017) in Powershell

On my Win11 PC I run two instances of Visual Studio concurrently. 2017 version for an 'API.cs' and 2022 version to run 'program.cs'. Recently I had 'program.cs' hang on me, so I opened Powershell to ...
Dazz's user avatar
  • 13
3 votes
2 answers
205 views

How can I modify this C# (inside powershell) so that it waits for the child process that it spawns to terminate?

This brilliant person Jborean93 has created a powershell script which in turn generates an .exe Called "noGui.exe" here I'll quote the code so you don't have to go find it: Add-Type -...
arker's user avatar
  • 61
0 votes
0 answers
69 views

Why are ETW events not triggered when using PS in a custom PowerShell host from C#?

I'm executing PowerShell scripts from within a C# application using the System.Management.Automation library. My goal is to capture script actions through ETW events from the Microsoft-Windows-...
Lifka's user avatar
  • 259
0 votes
1 answer
78 views

In C#, how do I run a Powershell script elevated and capture the output (no prompts/password)

I am writing a tool for my team to perform a list of tasks in a JSON file. Some of these tasks are for installing/updating programs. I can assume that those who use this tool have administrative ...
Cyberclops's user avatar
3 votes
1 answer
44 views

Reproduce Invoke-WebRequest behaviour in C# [duplicate]

I've exported a request from my Chrome browser using "Copy as PowerShell", trimmed it to a minimum and the script runs successfully: Invoke-WebRequest -Uri "https://www.sec.gov/data-...
vlad2048's user avatar
  • 191
0 votes
1 answer
183 views

The type initializer for '<Module>' threw an exception exception in Windows 11 24H2 machine

I am running the powershell script in .net 4.7.2. Its working fine on windows 11 machines, but its giving an error in windows 11 24H2 machine (not the exception). static void Main(string[] args) { ...
viveknuna's user avatar
3 votes
1 answer
89 views

C#.NET 8.0 running on Linux cannot access full AD group memberships larger than 1500 members

The System.DirectoryServices.AccountManagement library can't be used because it only works on Microsoft servers/workstations. The System.DirectoryServices.Protocols library enables me to access our AD ...
Rich Bayless's user avatar
0 votes
0 answers
95 views

Could not load file or assembly 'System.Security.Principal.Windows, Version=4.1.1.0

Description I have an application targeting .NET 4.7.2. There is a code to run the given PowerShell script it is working as expected. but only on the Windows 11 24H2 operating system machine the ...
viveknuna's user avatar
1 vote
2 answers
102 views

Why this does not work but similar power shell operation does

I have enabled all needed options using dism Method: public object SetKeyStatus(Dictionary<string, string> request) { if (!request.ContainsKey("Key") || !...
0___________'s user avatar
  • 68.5k
1 vote
1 answer
114 views

PowerShell: executing C# Class (FindFiles) as an Add-Type definition on a remote system using Invoke-Command is extremely slow

I want to find all Package.json files on a remote system using PowerShell. In order to optimize this, I found a C# class on the internet adjusted it and now would like to use it. This code runs really ...
AhYep's user avatar
  • 11
3 votes
1 answer
72 views

How can I output a PSCustomObject from a compiled Cmdlet?

I have a compiled Cmdlet that works with Hashtables. I would like to write a [pscustomobject] of the hashtable to the pipeline. In a PowerShell script block that would be accomplished using the ...
alx9r's user avatar
  • 4,303
1 vote
0 answers
40 views

Implement autocomplete in autorest with directives

I’m using Autorest to generate PowerShell cmdlets and I want to implement argument completion for a parameter dynamically using another cmdlet (e.g., Get-BsnOsmCliNSinstance). I’ve read about using ...
Amir Hossein Mir Mohammad's user avatar
3 votes
1 answer
72 views

In a compiled Cmdlet, how can I write an error from a thread job without burying the PositionMessage?

Errors from thread jobs written to the error stream by Receive-Job show the PositionMessage for the originating error. Consider, for example $job = Start-ThreadJob { 1/0 # error line } ...
alx9r's user avatar
  • 4,303
2 votes
1 answer
132 views

exchange online Get-DistributionGroupMember command not getting Initials

I am doing this PowerShell command Get-DistributionGroupMember but it is not returning the user's middle name. Is there something I am missing? Any other way to do this? public List<EmailGroup> ...
Jefferson's user avatar
2 votes
2 answers
135 views

Getting an exit code from powershell file invoked in C#

I am trying to have a powershell script called from a C# program give me the exit code of the powershell script. I have attempted it a few ways with no success. The PSObject from the invoke call ...
BrandonE's user avatar

15 30 50 per page
1
2 3 4 5
299