Questions tagged [powershell-sdk]

This tag is useful when the issue pertains to the development and maintenance of Powershell extends which use the generic Powershell Software Development Kit, as opposed to a provider-specific SDK.

The Windows PowerShell Software Development Kit (SDK) is written for command developers who require reference information about the APIs provided by Windows PowerShell. Command developers use Windows PowerShell to create both commands and providers that extend the tasks that can be performed by Windows PowerShell.

35 questions
2
votes
2 answers

How to support powershell tab expansion in psprovider?

I'm implementing Powershell PSProvider for some internal hierarchical data. Everything works fine, I can navigate through the tree with usual cd/dir commands, the only thing doesn't work is tab completion. What I can see is that Powershell calls…
2
votes
1 answer

Why does my powershell function fail to be called from C#?

Trying to use a powershell script with a function as follows: function MoveCompressFiles{ Param ( [Parameter(Mandatory=$true )] [string] $Des, [Parameter(Mandatory=$true)] [string] $Src ) Add-Type…
tthh
  • 31
  • 6
2
votes
1 answer

C# won't run PowerShell script

I want to call PowerShell script from my C# project but it wont work. When I run the code I don't get any errors(or I don't know where to find them). I also tried to run script from cmd and script works fine. My execution policy is set to…
2
votes
1 answer

Powershell ignores parameter passed via SessionStateProxy.SetVariable

I have the following Powershell script. param([String]$stepx="Not Working") echo $stepx I then try using the following C# to pass a parameter to this script. using (Runspace space = RunspaceFactory.CreateRunspace()) { …
Dave
  • 2,473
  • 2
  • 30
  • 55
1
vote
2 answers

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-Connect-MSGraph($ClientId, $TenantId,…
1
vote
1 answer

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(); runspace.Open(); Pipeline pipeline…
BurakBey
  • 55
  • 5
1
vote
1 answer

The state of the current PowerShell instance is not valid for this operation in C#

I am having below method which is being called for different PS scripts and I would like the PowerShell object to be created only once and for that I made the Powershell object as static(see below code). but then it gives me error The state of the…
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54
1
vote
1 answer

Whats the correct way to get output for this Powershell in C#

I am not getting any error below but I am also not getting the output. Below is the Powershell cmd and the C# method which is calling it. I would like to know if it is written correctly and how can I get the output as coming from powershell. It…
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54
1
vote
1 answer

Powershell command not recognized when calling from C#

This is in continuation to this Question here, I have a PowerShell command which I have created and am able to call the command in a PowerShell window, but when trying to call from C# method, I am getting error as the cmdlet is not recognized, I…
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54
1
vote
1 answer

PowerShell Object returns null

I have below command and it returns me null object . When I run the command separately in PowerShell window I get the right result. Below is my PowerShell method which is calling the command and the also the PowerShell command which I have defined.…
ZZZSharePoint
  • 1,163
  • 1
  • 19
  • 54
1
vote
2 answers

Invoked PS command to string

Is there way to convert invoked powershell command from C# to string?. Let's say for example i have something like this: PowerShell ps = PowerShell.Create(); ps.AddCommand("Add-VpnConnection"); …
Johny Wave
  • 111
  • 2
  • 11
1
vote
1 answer

WPF threading and custom Powershell host - Command execution stopped because the user interrupted the command

I have a WPF app with a powershell custom host that runs a script that is stored in an embedded resource. After loading, the user click the execute button and the script is Invoked but I see the following error: Command execution stopped because…
Jonesie
  • 6,997
  • 10
  • 48
  • 66
1
vote
1 answer

How can I run initialization code each time my snap-in is loaded?

I have a PowerShell snapin, and I would like to run a bit of initialization code (hooking some AppDomain events) each time my snapin is loaded (i.e. once for each powershell.exe process that is started). How can this be accomplished?
Mark
  • 11,257
  • 11
  • 61
  • 97
0
votes
1 answer

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 = ""; script = "Set-WinUserLanguageList -LanguageList…
bluefox
  • 175
  • 3
  • 16
0
votes
1 answer

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 (var ps = PowerShell.Create()) { …
Tim Meyer
  • 12,210
  • 8
  • 64
  • 97