Questions tagged [cmdlet]

A cmdlet is a lightweight Windows [tag:PowerShell] script that performs a single function.

-2
votes
0answers
13 views

Deploy SQL scripts to multiple environment using CmdletBinding and Param

I have two environment DEV and PRD where I need to deploy SQL Scripts, The SQL script are in a folder having 4 subfolders, Tables, Views, Stored Procedure, Others. I need to create a power shell ...
0
votes
1answer
32 views

Powershell C# Cmdlet Set InformationAction

I am creating the PowerShell cmdlet in C#. To enable support for pipeline I have used WriteObject to expose the output to the next cmdlet in the pipeline. However, now I want to display basic status ...
-1
votes
1answer
31 views

How to run an executable with Powershell [duplicate]

From a physical computer, I want to run an executable on a remote virtual machine. The executable is already on the remote virtual machine. The cmdlet I use is: $command ="c:\users\<username>\...
0
votes
0answers
47 views

Pass command to powershell start-Process in Argument-List

I want to pass a cmdlet to be executed immediately in child Process. ---> $cmd = $(Get-Item -FORCE "PATH\to\Folder").Attributes="Normal" Start-Process powershell -ArgumentList " multiple $cmd Here" ...
0
votes
1answer
32 views

Ambiguous SwitchParameter binding in PoweShell cmdlet

I want to add two switch parameters to my custom PowerShell cmdlet like this: [Parameter(Mandatory = false, ParameterSetName ="p1")] public SwitchParameter switchOne { get; set; } [Parameter(...
1
vote
2answers
211 views

How to save each line of text file as array through powershell

If I have a text file, C:\USER\Documents\Collections\collection.txt that has the following information: collectionA.json collectionB.json collectionC.json collectionD.json I am wondering how, ...
2
votes
1answer
27 views

What is an appropriate debugging workflow for Powershell Core modules?

My company has a .NET Powershell module, written in C# to allow advanced users to automate tasks in our product. Currently it targets Powershell 5 using .NET 4.6.1. We would like to allow customers ...
0
votes
0answers
34 views

Powershell cmdlet ouput

This is the prompt for a powershell cmdlet: Confirm Are you sure you want to perform this action? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): The [A] ...
0
votes
1answer
86 views

Where are the Powershell cmdlets for TFS 2017?

I have a 2008 software with a TFSBuild.proj on a TFS repository that has been migrated from 2008 to 2017. I have a TFS 2017 build agent on which has been installed Visual Studio 2017 (15.7.6). There ...
1
vote
1answer
39 views

How to terminate the script execution in case commandlet encounters error

I need to terminate the whole script execution if command let encounters the error. The whole script after that must never execute. In my case, If I use ThrowTerminatingError, it just stops the ...
1
vote
0answers
38 views

How to correctly address resource for C# Cmdlet helpmessage localization

I'm trying to activate localization for parameters in my Cmdlets developed for PowerShell 5. I have this parameter, which I'm trying to localize by supplying the values for the helpmessage as seen ...
2
votes
1answer
327 views

Net User $userName /domain

I am trying to create a module for our support team which will contain some tools we use on daily basis but we used CMD until now. One of the commands we use is net user $username /domain in order to ...
0
votes
1answer
76 views

Powershell C# commandlets Conditional switch parameters

I need to apply conditional switch parameter only if other parameter is provided. Can any body let me know how can I achieve this in C# I want following way command let accessible on powershell ...
2
votes
2answers
30 views

Powershell run space write protected variables ( not replace able )

I need to define a container in powershell which cannot be modify able once it is created. I know there is a way, by which variables can be created as hidden in current run space but still somehow ...
1
vote
1answer
95 views

Writing a C# PowerShell Cmdlet, how to output debug logging to TeamCity caller

I am writing a PowerShell Cmdlet in C# and I need to add some diagnostic logging to the script so that I can evaluate the behavior through TeamCity. Having experimented with WriteVerbose with the -...
0
votes
1answer
33 views

error powershell c# visual studio

I have got a simple class libary project in visual studio: using System; using System.Linq; using System.Management.Automation; namespace EdoX_auslesen_xml { [Cmdlet(VerbsCommon.Get, "DemoNames"...
0
votes
0answers
21 views

powershell cmdlet in visual studio 2017, deserialization method

I have got a problem with undestanding powershell cmdlet. Task is, to deserialize a xml file. I have got a folder with a lot of xml files, I would like to read in an filter certain information using ...
0
votes
1answer
40 views

Parsing not working correctly for Powershell

I have written the following logic to check status of service: $status=@() if($var1 -match "True") { Write-Output "Service Enabled" } else { $status+="Service not Enabled" Write-Output "Service not ...
0
votes
1answer
44 views

Replacing multiple if statements

I am using PS version 5.0 and I have quite a few if statements which might grow over time. if ($hostname -like "**12*") { Write-Output "DC1" } elseif ($Hostname -like "**23*") { Write-Output "...
0
votes
1answer
45 views

Powershell Grouping acting differently in different versions

Question: How do I write this so it gives the same result in v4 and v5? I am trying to group the following dataset by SiteCode. I have a dataset as follows [Array of Hashes]: Assume AppointmentId ...
0
votes
1answer
58 views

ADSI not validating correctly?

I have a CSV with 1500+ users there are 30 users per class OU, and then 6 class OU's per Intake OU. What I'm trying to achieve is, foreach (user in CSV), check if OU exists, then check if parent OU ...
0
votes
2answers
66 views

Storing EventViewerLogs in Excel spreadsheet from Powershell

I want to store the output of: $Application = Get-EventLog -LogName Application | Where-Object {($_.EntryType -like 'Error' -or $_.EntryType -like 'Warning')}; in an excel spreadsheet. I tried ...
1
vote
1answer
32 views

Conditional Mandatory in PowerShell

I'm trying to make a parameter mandatory, but only if another parameter uses certain ValidateSet values. It seems that using a code block on Mandatory doesn't work as expected. function Test-Me { ...
0
votes
1answer
33 views

Shorter execution of powershell script

Say I have a script to be executed in a single call, how do I do it? Like, say I have a powershell script saved at E:\Fldr\scrpt.ps1. Now if I have to normally execute that script is PowerShell ISE ...
0
votes
0answers
92 views

'Import-Module' not able to load cmdlet dll

I have created a custom cmdlet to get the TFS Version control Server object (Get-VersionControlServer) in C#. I want to use this cmdlet in my TFS 2017 MSBuild build Definition, in the MsBuild.ps1 file ...
0
votes
0answers
49 views

How to add help for an dynamic parameter?

So, I've created a cmdlet with a dynamic parameter: public class MyCmdLet : IDynamicParameters { public string StandbyFilePath => _standbyFilePathDynamicParameter.StandbyFilePath; private ...
1
vote
1answer
1k views

Powershell - Cannot convert value of type “System.Management.Automation.PSCustomObject” to type “System.Management.Automation.PSCustomObject”

I am working with Powershell 4 under Windows 7 and I have cmdlet defined like this: Function Transfer-File { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [System....
-3
votes
1answer
209 views

How to close cmd in batch file

start cmd /k /k: is compulsory which will execute. launching many command propmts can be done as below. start cmd /k Call rc_hub.bat 4444 start cmd /k Call rc_grid1.bat 5555 start cmd /k Call ...
0
votes
1answer
62 views

Splat hashtables contained in an array

Given a list of hashtables $adminprinters | ConvertTo-Json [ { "Brand": "HP", "IP": "10.8.200.200", "Name": "Admin-Tech-HP4700" }, { "Brand": "HP", ...
0
votes
1answer
299 views

How can I upgrade Power shell version from 3.0 to 4.0 or 5.0

I am using Windows 8 and the Power shell version is 3.0 but i want to use cmdlet which is not supported PSversion 3.0 so how can i update version 4.0 or more
0
votes
0answers
38 views

Using Powershell to gather xml data, file path and naming help (easy!)

Trying to adapt some old code written by a former employee to suit my needs. The code performs a bunch of checks and then searches the root folder for xml files to rip. Currently everything under the ...
6
votes
2answers
295 views

Service Fabric/Jenkins integration issue

I am trying to automate deployment to Azure Service Fabric with Jenkins and ServiceFabric PowerShell extension. Jenkins ServiceFabric plugin is not a good option in my case due to lack of control and ...
-2
votes
1answer
67 views

C# PowerShell Cmdlet input prompt

Could anyone please provide a C# code sample showing how to prompt for user input in a custom PowerShell Cmdlet? I find plenty of articles on how to pass parameters to a Cmdlet, but little to none ...
0
votes
1answer
38 views

Create powershell cmdlet that processes each path received from dir

I'm trying to create a cmdlet written in powershell that can accept each path from dir command and run a powershell function on this path. Example: PS> dir *.ext | Convert-xyz Here's what I ...
1
vote
1answer
94 views

How can I get the original pipeline object when using ValueFromPipelineByPropertyName?

I'm building a Cmdlet in C#. When binding parameters using ValueFromPipelineByPropertyName=true, I often would like to pass the original pipeline object from which the properties were bound back into ...
0
votes
1answer
290 views

New-Item PowerShell directory tree with multiple directories

I know how to use New-Item in PowerShell so I can create some directories. But can I in anyway make this code shorter? New-Item 'c:\drivers\Windows\Network\32bit PowerShell' -Type Directory New-Item '...
0
votes
3answers
74 views

How to insert a cmdlet into a string in powershell

Say I want to tell the time in a string, just like this Write-Output "It's now (Get-Date)" That doesn't seem to work, as opposed to: $time = Get-Date Write-Output "It's now $time" How can I ...
0
votes
0answers
484 views

Powershell Core “Could not load file or assembly 'netstandard, Version=2.0.0.0”

I'm trying to develop a PowerShell Core module that depends on a helper library written with .NET Standard 2 in mind. My helper library works fine according to my tests, and it does what it should. ...
0
votes
2answers
518 views

Using Powershell to test-path on a network drive

I can't get the Test-Path cmdlet to find a folder on a remote system's additional drive. The following works for the system drive. Test-Path -PATH '\\ServerName\C$\FolderName' The next example ...
1
vote
2answers
378 views

In Powershell how to find the module for a cmdlet

I'm trying to setup a VM with Hyper-V. I need to run get-vmserver and some related comdlets but I can't find what module they are in. When I run: (get-command -name start-transcript).modulename I ...
1
vote
1answer
203 views

AWS PowerShell update CloudFront distribution

I am trying to update my CloudFront distribution using AWSPowerShell module for PowerShell. When I use the update cmdlet from the module, I always get an error about not providing the "IfMatch" ...
0
votes
1answer
51 views

How to access PSObject DefaultKeyPropertySet details in .NET with C#

I am trying to implement a cmdlet in C# that uses the PSStandardMembers.DefaultKeyPropertySet.ReferencedPropertyNames collection to build a single string key based on the property values of a PSObject....
0
votes
1answer
206 views

Use function from powershell cmdlet dll

Is it possible to add DLL that implements PowerShell cmdlet to C# project and call its functions as you normally do with classes? The problem is that cmdlet doesn't have suitable functions to call. It ...
0
votes
2answers
435 views

Pass IStorageContext as parameter of a Cmdlet - Unable to find type [IStorageContext]

I'm going to create a Cmdlet which accepts IStorageContext as parameter. But when running the cmdlet, it throws a TypeNotFound exception stating: Unable to find type [IStorageContext] Here is the ...
1
vote
1answer
538 views

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.$...
0
votes
1answer
1k views

Powershell String Length Validation - The script Doesn't validate input but Creates a file in each execution

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 ...
0
votes
1answer
41 views

Network profile missing null

I am trying to retrive nics from multiple Vms, for loop is created for nic such as it will check if the vm has multiple nic assosiated with it, if yes then it will set it as primary.if the vm is ...
1
vote
1answer
496 views

Not able to select subscription ID in azure

I am using below code to select subscription id in Power shell script, but when i click on the subscription id it does not select... $subscriptionId = (Get-AzureRmSubscription | Out-GridView -Title '...
1
vote
1answer
172 views

PowerShell advanced function output PipelineVariable doesn't work

I created an advanced function to get the mac address from a VM running on VMware ESXi. function Get-MacFromVm { [CmdletBinding(SupportsShouldProcess=$true)] Param( # The name of the ...
1
vote
2answers
1k views

In Powershell, Invoke-expression is not working when entering space in the path

I have a query like when I try to execute the expression which contains a path with space, I am getting an error as below. Code: $path="E:\Test\My space\Log" Invoke-Expression $path E:\Test\My: ...