Questions tagged [powershell-cmdlet]

Quote from Microsoft site: "A cmdlet is a lightweight command that is used in the PowerShell environment. The PowerShell runtime invokes these cmdlets within the context of automation scripts that are provided at the command line. The PowerShell runtime also invokes them programmatically through PowerShell APIs"

Ref: Cmdlet Overview

882 questions
8
votes
2 answers

Running PowerShell cmdlets in C#

I need to run powershell cmdlets using C# in Visual Studio Console. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Management.Automation; using System.Threading; using…
8
votes
2 answers

Parameterattribute default value (C# cmdlet) in PowerShell

I'm designing a cmdlet using plain C#. Is it possible to define a default value for a parameter? Script cmdlet: [Parameter] [string] $ParameterName = "defaultValue" Which is the equivalent for C#? [Parameter] public string ParameterName { get; set;…
fra
  • 3,488
  • 5
  • 38
  • 61
8
votes
3 answers

Powershell and TFS: tf.exe versus Power tools TFS cmdlets?

I'm in the middle of creating a script to do large amount of moves in my TFS instance. I have the tfs cmdlets available with the 2010 TFS Power Tools, but the get-help documentation for them is very sparse. Specifically, Add-TfsPendingChange doesn't…
bwerks
  • 8,651
  • 14
  • 68
  • 100
8
votes
1 answer

Conditionally excluding cmdlet arguments that are null or empty

I've written a script that calls the New-Service cmdlet to create a Windows service: New-Service -Name $Name -BinaryPathName $ExecutablePath ` -Credential $Credential -DisplayName $DisplayName ` -Description $Description -StartupType…
Simon Elms
  • 17,832
  • 21
  • 87
  • 103
8
votes
3 answers

creating powershell script to backup a file and append the date

Currently I have a one line batch file to back up a file. I run it manually when I need to back up a file. The only thing I would like to add to it is the current date. Here is what I have: xcopy /W /Y ACTIVE.DB ACTIVE.DB.BACKUP the destination…
Sam Carleton
  • 1,339
  • 7
  • 23
  • 45
8
votes
1 answer

How to import a Cmdlet from a DLL

Is it possible to import and invoke a Cmdlet from a DLL that is not in the PATH directories? I want to write a build script with powershell that is able to compress the results. Therefore I found 7Zip4Powershell Cmdlets (Source), but I am unable to…
Karsten
  • 1,814
  • 2
  • 17
  • 32
8
votes
2 answers

How to call PowerShell cmdlets from C# in Visual Studio

I'm creating a PowerShell cmdlets from Visual Studio and I can't find out how to call cmdlets from within my C# file, or if this is even possible? I have no trouble running my cmdlets one by one, but I want to set up a cmdlet to run multiple cmdlets…
Bjorn
  • 723
  • 2
  • 11
  • 29
8
votes
3 answers

What is the best practice for keeping state between calls to Powershell Cmdlets?

I am a complete newbie to Powershell development and I am trying to write a Powershell Cmdlet in C# that will be used as an interface to a REST API. I would like to have some kind of setup Cmdlet where the user will be prompted for an Uri, username…
RobinHu
  • 374
  • 2
  • 14
8
votes
1 answer

Powershell - Get Variable from C# Cmdlet

I'm writing a C# Cmdlet that needs to get the value of a global script variable. How do I do it? I noticed that the Runspace has SessionStateProxy.GetVariable method. Can I access the runspace from a C# Cmdlet? Thanks!
Yuval Peled
  • 4,988
  • 8
  • 30
  • 36
8
votes
1 answer

Is it possible to share properties and comments between Powershell cmdlets in c#?

When exposing a set of related functions in Powershell cmdlets, is it possible to share the property names and summary help to normalize these across cmdlets in an assembly? I know that this can be done with derived classes, but this solution is…
pennyowe
  • 165
  • 7
7
votes
3 answers

Set Value of Nested Object Property by Name in PowerShell

I want to set value of nested object property using PowerShell. When you are trying to set the value of the first level properties, it's quiet simple: $propertyName = "someProperty" $obj.$propertyName = "someValue" # ← It works For nested…
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
7
votes
2 answers

Select-String in Powershell only displaying part of the line from a text file, need it to display whole thing

I am trying to write a simple PS script to check large .txt log files for a short string: "SRVE0242I:" $lines = Select-String -Path $logDir -Pattern "SRVE0242I:" | Select-Object line | Out-String On output though, it only displays the…
user3431504
  • 149
  • 1
  • 1
  • 9
7
votes
3 answers

How to convert .cs file to a PowerShell cmdlet?

Can anyone help me to convert a C# .NET program to PowerShell cmdlet? I am very new to this area. Please help me to get out of this checkpoint! Regards, Arun
Arun
  • 580
  • 6
  • 11
  • 17
7
votes
3 answers

Are there Powershell cmdlets that install and remove Windows drivers?

Note: For this question, when I refer to "Windows drivers" I mean .inf and associated files which can otherwise be installed by right-clicking the .inf and clicking "Install" in Windows Explorer. I do not mean any kind of setup.exe-style executable…
alx9r
  • 3,675
  • 4
  • 26
  • 55
7
votes
1 answer

How to get current working directory inside a Cmdlet

I am writing a Cmdlet for PowerShell in C#. I am subclassing a Cmdlet and NOT a PSCmdlet. Is there a way to get the current directory from PowerShell? I could do so with the PSCmdlet using GetVariableValue("pwd"). But in the Cmd class I do not have…
Hemisphera
  • 816
  • 6
  • 23