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
5
votes
1 answer

PowerShell Commands Adding EF Migration by Code

Wondering if anyone can help me solve this. I am able to use the Package Manager Console to Enable-Migrations, Add-Migrations etc etc. But I want to be able to do this using c# code via the PowerShell object What I have so far is: var ps =…
5
votes
1 answer

How do I define functions within a CmdletBinding() script?

I'm writing a script that I'd like to use PowerShell's CmdletBinding() with. Is there a way to define functions in the script? When I try, PowerShell complains about "Unexpected toke 'function' in expression or statement" Here's a simplified example…
mojo
  • 4,050
  • 17
  • 24
5
votes
2 answers

Trying to create. initialize, and format VHD disks

Some background: I work in a lab environment and have a number of issues that come through that require VHDs to be created and attached to VMs for stress testing. I have come up with a script that allows the user to make the process as simple as…
Gavin_Talyn
  • 107
  • 1
  • 2
  • 8
5
votes
2 answers

Can I control the DateTime format displayed by my cmdlet?

I own a cmdlet with a DateTime property that represents the timestamp of an event on a server. The cmdlet reads a log on the server and outputs some information. Since a bunch of events can happen in a short window, millisecond precision is…
Troyen
  • 1,398
  • 2
  • 23
  • 37
5
votes
1 answer

LiteralPath option for cmdlet

In most example that I see in tutorials and books, the -LiteralPath option is almost never used by default (the -Path option seems to be preferred). Because the -LiteralPath option allows to use reserved characters (e.g. []), I don't understand why…
m_power
  • 3,156
  • 5
  • 33
  • 54
5
votes
2 answers

Change Azure website web hosting plan mode using Powershell

I've been reading the following article that describes how to change the web hosting plan for your site. http://azure.microsoft.com/en-us/documentation/articles/azure-web-sites-web-hosting-plans-in-depth-overview/ That seems to work fine but if I…
emp
  • 4,926
  • 2
  • 38
  • 50
5
votes
2 answers

Using read-host cmdlet when execute powershell script file in MSBuild

All , I am trying to execute a external power shell script file in the MSBuild. But every time when PS run the cmdlet Read-Host. The MSBuild seems stop. and doesn't prompt me to input . I don't know what happen to it . Seems the console is in…
Joe.wang
  • 11,537
  • 25
  • 103
  • 180
5
votes
2 answers

How to hide a parameter in Cmdlet

I want to hide a PowerShell Cmdlet parameter from user. Is there any way to do this in C#? I want to use this parameter within my code to trigger the same cmdlet with the hidden parameter. I use PowerShell 2.0. Thanks.
Hem
  • 619
  • 13
  • 26
5
votes
1 answer

Add Powershell Snapin for Powershell Module and Import Multiple Times

I would like to use the SqlServerCmdletSnapin for my custom Powershell Commandlet I am building. If I add the following code to the beginning of my PSM1: if ( (Get-PSSnapin -Name sqlserverprovidersnapin100 -ErrorAction SilentlyContinue) -eq $null…
Blake Blackwell
  • 7,575
  • 10
  • 50
  • 67
5
votes
1 answer

Difference between Cmdlet.EndProcessing and Cmdlet.StopProcessing

When writing Powershell cmdlets, what is the difference between EndProcessing and StopProcessing? They sound the same, their descriptions are just about the same, and latter doesn't appear in the cmdlet lifecycle documentation.
Justin R.
  • 23,435
  • 23
  • 108
  • 157
5
votes
3 answers

Setting GPO security filter with powershell Set-GPPermissions cmdlet

According to Microsoft the cmdlet Set-GPPermissions accepts the option "-replace": "This ensures that the existing permission level is replaced by the new permission level." I import a GPO from PowerShell. After that I want to set the security…
user1458620
  • 205
  • 1
  • 4
  • 12
5
votes
6 answers

get a folder path from the explorer menu to a powershell variable

is it possible to open a explorer window from powershell and store the path selected in the explorer, to a variable? to open explorer window from powershell PS C:> explorer
naveejr
  • 735
  • 1
  • 15
  • 31
4
votes
2 answers

Windows cmdlet for conditional out-file file creation

Get-Service AppHostSVC,FTPSVC,IISAdmin,MSFTPSVC,W3SVC,WAS,WMSVC | Select Name,Status,DisplayName| Where-Object {$_.Status -EQ "Stopped"} ConvertTo-Html | Out-File -FilePath c:\checker.html In the above cmdlet, how can I add a…
sakworld
  • 77
  • 5
4
votes
1 answer

Sets of mutually exclusive parameters in PowerShell: Why is this ambiguous?

I've been trying to get multiple sets of mutual exclusions to work. I want "Width" mutually exclusive to "WidthReset" and "Height" to be mutually exclusive with "HeightReset". Help for the cmdlet shows: Get-ArgTest [-Width ] [-Height ]…
joeking
  • 2,006
  • 18
  • 29
4
votes
1 answer

How to execute MSI file on Github Actions (windows-latest runner)

Context I created a Github Actions workflow that generates a .msi file that I wan't to execute afterwards to test if the application is working as expected. The workflow implementation is as below build-windows: runs-on: windows-latest …
GuiFalourd
  • 15,523
  • 8
  • 44
  • 71