43 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
2
votes
2
answers
209
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 ...
1
vote
1
answer
72
views
How to Restrict PowerShell SDK to Limit Script Access to Specific Callback Methods in a C# Application?
In my C# application I want to use the PowerShell SDK to allow user-provided PS scripts to interact with limited parts of the application through callbacks. I want to restrict what these scripts can ...
1
vote
1
answer
91
views
C# can't convert from string to runspacemode?
So writing a C# program that uses a powershell script as follows
PowerShell allowtorthroughwindowsfirewallinbound = PowerShell.Create("New - NetFirewallRule - DisplayName Allow TOR through ...
user avatar
user24983509
1
vote
1
answer
81
views
Handling Errors When Invoking PowerShell Script from C#?
I am trying to invoke a powershell script that makes use of tokens.
var results = powerShell.Invoke();
if (powerShell.HadErrors)
{
foreach (var error in powerShell.Streams.Error)
{ ...
1
vote
1
answer
157
views
What's the default PSHost implementation (for use in a RunspacePool)?
I'm trying to create a RunspacePool with an initial session state and a count of min/max runspaces. However, the only constructor on RunspaceFactory that supports all those parameters also requires a ...
1
vote
1
answer
595
views
ORACLE ManagedDataAccess Core in PowerShell 7
I have a simple .NET 7 class library referencing this NuGet package (NO other ORACLE packages are included):
<PackageReference Include="Oracle.ManagedDataAccess.Core" Version="3.21....
2
votes
1
answer
150
views
C# using Powershell.AddParameter with two conditions
I'd like to call a PowerShell script in c#. In Terminal the command would look like
get-mailbox -RecipientTypeDetails "EquipmentMailbox","RoomMailbox"
I can get it to run if I ...
3
votes
2
answers
167
views
How can it be determined if a caller is using PowerShell 5.1 or a newer version from C#?
From PowerShell we can easily check if a caller is using Windows PowerShell 5.1 or a newer version using the $PSVersionTable automatic variable:
if ($PSVersionTable.PSVersion -ge '7.0') {
# do 7+ ...
0
votes
1
answer
97
views
Running PowerShell Script from C# has no effect
I have created the following C# code to run a powershell script:
static void Main(string[] args)
{
PowerShell ps = PowerShell.Create();
string script = "";
...
0
votes
1
answer
51
views
Why does PowerShell.Invoke contain regular messages in the error stream
I am using Microsoft.PowerShell.SDK (Version 7.3.3) in order to clone a git repository from C# like this:
(Note: I know there is libgit2sharp, but it doesn't support all of my use cases).
using (...
1
vote
2
answers
2k
views
Can't get CustomSecurityAttributes for Azure AD users with MS Graph Powershell SDK
For the context, I'm building an app that will read and update the Custom Security Attributes of Azure AD users. I'm using the beta version.
Here is my code:
# Connect to the client
Function Invoke-...
1
vote
1
answer
261
views
Cannot Execute Command "New-ItemProperty" Properly
I am trying to insert a registry entry with a PowerShell script using C#. This is my code:
public void ExecuteCommand(string script)
{
Runspace runspace = RunspaceFactory.CreateRunspace();
...
1
vote
2
answers
1k
views
Capturing all streams in correct sequence with PowerShell SDK
I'm executing a script with the PowerShell SDK, which makes use of all different streams (information, warning, verbose, ..). I can capture the output from them correctly, but not in the sequence they ...
0
votes
1
answer
92
views
.Net Powershell SDK 6.2.6 - Why are PKI module commands unavailable on some systems?
The short question
Why, when I run the Get-Command powershell command within a .NET 5.0 application using the Microsoft.PowerShell.SDK nuget package I get different results on different systems, and ...
0
votes
0
answers
56
views
IIS 10.0 Could not connect to NuGet feed via PowerShell
I am doing an automatic build of C# applications on a web server with IIS 10.0, my code generates a command for PowerShell.SDK.
using(PowerShell pws = PowerShell.Create())
{
var cmd = $"set-...