cmdlet

Clear-RecycleBin cmdlet's progress bar output is shown incorrectly

╄→尐↘猪︶ㄣ 提交于 2020-07-20 03:52:26
问题 Is the first time I'm using the Clear-RecycleBin cmdlet, and it seems obvious that this cmdlet paints a typical command-line progress bar that I think it should be filled with symbols or maybe color blocks from start to end, or maybe it should just print a percentage value in the middle of the bar, I don't know exactly because as I'm saying is the first time I'm using this cmdlet, however, seeying the image below its obvious the progress bar output is wrong. The proggress-bar is totally

Clear-RecycleBin cmdlet's progress bar output is shown incorrectly

偶尔善良 提交于 2020-07-20 03:52:19
问题 Is the first time I'm using the Clear-RecycleBin cmdlet, and it seems obvious that this cmdlet paints a typical command-line progress bar that I think it should be filled with symbols or maybe color blocks from start to end, or maybe it should just print a percentage value in the middle of the bar, I don't know exactly because as I'm saying is the first time I'm using this cmdlet, however, seeying the image below its obvious the progress bar output is wrong. The proggress-bar is totally

Powershell String Length Validation

孤人 提交于 2020-03-03 09:18:46
问题 I created a really simple HelloWorld.ps1 Power-shell script which accepts a Name parameter, validates its length and then prints a hello message, for example if you pass John as Name , it's supposed to print Hello John! . Here is the Power-shell script: param ( [parameter(Mandatory=$true)] [string] $Name ) # Length Validation if ($Name.Length > 10) { Write-Host "Parameter should have at most 10 characters." Break } Write-Host "Hello $Name!" And here is the command to execute it: .\HelloWorld

LiteralPath option for cmdlet

安稳与你 提交于 2020-01-24 08:40:07
问题 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 it is not used more often (if not, all the time). Is it because it is preferred to escape reserved characters manually, because it has a high performance cost, because not all cmdlet support this option or because something else? 回答1: One thing to

How to unit test a PowerShell Core binary cmdlet in C#

我的未来我决定 提交于 2020-01-14 03:17:08
问题 I've written a simple PowerShell cmdlet in C# to show off the problem I'm encountering. Feel free to clone the repo, or fork it and get it working and submit a PR, or just look at the source code to see exactly what I am doing. I've created a simple PowerShell Core cmdlet using the PowerShellStandard.Library NuGet package. I'm using xUnit and am trying to run a unit test against the PowerShell cmdlet that I've created. The problem is that when I call the .Invoke() method of the cmdlet

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

别等时光非礼了梦想. 提交于 2020-01-11 09:24:07
问题 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 回答1: Maybe this script is what you want: Function Select-FolderDialog { param([string]$Description="Select Folder",[string]$RootFolder="Desktop") [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null $objForm = New-Object System.Windows.Forms.FolderBrowserDialog $objForm.Rootfolder =

Export Powershell 5 enum declaration from a Module

断了今生、忘了曾经 提交于 2020-01-02 02:40:30
问题 I have an enum type defined within a module. How do I export it to be accessible from outside once the module has been loaded? enum fruits { apple pie } function new-fruit { Param( [fruits]$myfruit ) write-host $myfruit } My advanced function takes the enum instead of the ValidateSet which works if the enum is available, but fails if it isn't. Update: Separating it into a ps1 and dot-sourcing it (ScriptsToProcess) works, however I would wish that there's a cleaner way. 回答1: You can access the

Powershell Add-Member - But without “Value” and “Count” elements in JSON

喜夏-厌秋 提交于 2020-01-01 19:14:14
问题 I am successfully adding a member to my JSON, but I end up with unwanted elements. What I am trying to add is the element inside "Value" that is appearing in the resulting JSON. { "Block1": value1, "Block2": value2, "Block3": [] } Then doing the Add-Member cmdlet. $objectFromJson | Add-Member -NotePropertyName "Block3" -NotePropertyValue $newblock -Force I realize I do not have to do the -Force part, but in my working code, my JSON string is parsed to an object using ConvertFrom-Json and that

cmdlet says parameter cannot be retrieved: expression must be readable

冷暖自知 提交于 2019-12-25 01:50:39
问题 My cmdlet has a Get-Deal command, which will receive value from pipeline: [Cmdlet(VerbsCommon.Get, "Deal")] public class GetDealCmdlet : InsightBaseCmdlet { private List<Object> _legalentities = new List<Object>(); [Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true,ValueFromPipelineByPropertyName = true)] public List<Object> Legalentity { set { _legalentities = value; } } protected override void ProcessRecord() {...} } It works fine if I passed a list of string or other types

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

本小妞迷上赌 提交于 2019-12-22 09:25:29
问题 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 of what I'm trying to do. [CmdletBinding()] param( [String] $Value ) BEGIN { f("Begin") } PROCESS { f("Process:" + $Value) } END { f("End") } Function f() { param([String]$m) Write-Host $m } In my case, writing a module is wasted overhead. The