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
14
votes
3 answers

Custom PowerShell Host and Converting PSObject back to base type

When hosting the PowerShell runtime is it possible to convert a PSObject back into its original type some how? For example: I have a cmdlet that calls WriteObject and pushes a collection of ClassXzy in the pipeline. When I call PowerShell.Invoke…
Adam Driscoll
  • 9,395
  • 9
  • 61
  • 104
7
votes
5 answers

How to pass $_ ($PSItem) in a ScriptBlock

I'm basically building my own parallel foreach pipeline function, using runspaces. My problem is: I call my function like this: somePipeline | MyNewForeachFunction { scriptBlockHere } | pipelineGoesOn... How can I pass the $_ parameter correctly…
6
votes
1 answer

In a PowerShell Provider, when do you refresh vs cache data?

I am writing a PowerShell provider in C#. The provider exposes an applications domain objects through a drive-like interface. For example: my:\Users\joe@blow.com my:\Customers\Marty This data ultimately comes from a database. I have been unable to…
Craig Celeste
  • 12,207
  • 10
  • 42
  • 49
5
votes
1 answer

Passing argument from C# to called PowerShell Script

I have the following function in my C# file: private void RunScriptFile(string scriptPath, string computerName, PSCredential credential) { RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace =…
sporty_1993
  • 133
  • 10
4
votes
1 answer

Call function from module inside a runspace

I have some functions in a module I would like to call from a runspace but It´s not working. I assume that I somehow have to send the module to the runspace. The example below works fine. $hash =…
4
votes
2 answers

Powershell GUI Freezing, even with runspace

I am creating a powershell script with a GUI, that copies user profiles from a selected source disk to a destination disk. I've created the GUI in XAML, with VS Community 2019. The script works like this : you select the source disk, the destination…
Oscar Loret
  • 65
  • 1
  • 7
4
votes
1 answer

How to get ScriptProperty Values of PSObject.Properties in C#?

I am trying to get drive information for a server through PowerShell 6.0 using the 'GET-PSDrive' command. Running the command directly in PowerShell, I see the values for 'Used' and 'Free' within the output table, but running the same command in…
mfree
  • 80
  • 1
  • 7
4
votes
2 answers

Powershell editor with intellisense that I can embed into my program?

I have a C# application and want to allow people to write powershell code within my app. Does anyone know of a powershell editor with intellisense that fits the bill??
makerofthings7
  • 60,103
  • 53
  • 215
  • 448
3
votes
2 answers

PowerShell running local from published Single Exe fails (without IncludeAllContentForSelfExtract)

Exceptions when running a single exe file using PowerShell. Computer: Windows 10 (latest patches) PowerShell SDK: 7.2.4 Application: Console net6.0 Code: using System.Management.Automation; Console.WriteLine("Test PowerShell Runner!"); var…
3
votes
1 answer

How to execute a powershell script using c# and setting execution policy?

I tried to combine two answers from stackoverflow (first & second) InitialSessionState iss = InitialSessionState.CreateDefault(); // Override ExecutionPolicy PropertyInfo execPolProp = iss.GetType().GetProperty(@"ExecutionPolicy"); if (execPolProp…
3r1c
  • 376
  • 5
  • 20
3
votes
1 answer

The RunSpace and its closure

While working with a script that uses a RunSpace, I found that it takes up more and more system memory. As far as I understand, this is due to the fact that open RunSpace do not close when completed. They remain in memory, accumulating…
3
votes
1 answer

Cant run ps1 script from out program files folder

I can run this script perfectly from my desktop: private void Sleep_Click(object sender, EventArgs e) { PowerShell ps = PowerShell.Create(); ps.AddScript(@"D:\Desktop\alllightsoff.ps1"); ps.Invoke(); } But…
IIIdefconIII
  • 353
  • 2
  • 5
  • 13
2
votes
1 answer

Powershell 7 SDK PSCmdlet - difference between GetCmdlet and GetCommand

With my first C# based Powershell cmdlet I ran into an issue of how to run "existing" cmdlets from within my custom cmdlet. Along the way I found the following: InvokeCommand.GetCmdlet("Compress-7Zip") and InvokeCommand.GetCommand("Compress-7Zip")…
Jacques
  • 6,936
  • 8
  • 43
  • 102
2
votes
0 answers

Setting a proxy within a powershell script that is started by a C# application

I have a test .Net core 3.1 c# console app which creates a new Runspace and runs a powershell script. var Session = InitialSessionState.CreateDefault(); Session.ImportPSModule("MicrosoftTeams"); var pool =…
Rich79
  • 23
  • 5
2
votes
0 answers

Data From PSObject C#

I was trying to run a powershell cmdlet on my C# application to get system information. Collection a = PowerShell.Create().AddScript("Get-NetIPConfiguration -InterfaceAlias \"Беспроводная сеть 2\"").Invoke(); In response to my request, I…
JVG
  • 31
  • 3
1
2 3