cmdlets

Understanding Cmdlet positional parameter

两盒软妹~` 提交于 2019-12-10 18:07:19
问题 All, Forgive me I am a newbie for the Power Shell , Currently I was reading book Windows PowerShell CookBook try to get start with it. So far, Everything make sense to me except one thing, I was totally confused with the Positional Parameter to Cmdlet . For example: Select-String The syntax is following : Select-String [-Pattern] <String[]> [-Path] <String[]> [-AllMatches] [-CaseSensitive] [-Context <Int32[]>] [-Encoding <String>] [-Exclude <String[]>] [-Include <String[]>] [-List] [-NotMatch

Call azure powershell cmdlet from c# application fails

别来无恙 提交于 2019-12-10 09:47:41
问题 I'trying to automatize the process of deploying to azure cloud. My powershell script that do that, works like a charm when executing it from azure powershell commandline. When I try to invoke the same script from c # application it fails . This is my code: internal void RunPowerShellScript(string scriptPath, Dictionary<string, string> arguments) { RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace

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

橙三吉。 提交于 2019-12-10 03:54:18
问题 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 and password to the REST API and then call Cmldlets like Get-Item without having to enter those parameters. Pretty much like the Azure provider for Powershell works where you can set the current subscription by calling Select-AzureSubscription and

How to get/set/update registry value through group policy cmdlet of Windows PowerShell?

♀尐吖头ヾ 提交于 2019-12-07 18:43:42
问题 I have configured the EventForwarding Manually but I was wondeing If I could do it programmatically and I came across the Group Policy Cmdlets which seems to be the solution. Here is what I am trying to configure manually in the image below. When I run the Get-GPO -all cmdlet I don't see any GPOs related to Event Forwarding. However when I ran the Get-GPResultantSetOfPolicy with the specified path of an XML file, I got to see my configuration of the Subscription manager of the Event

Referencing a file containing square brackets ([]) in it's path

给你一囗甜甜゛ 提交于 2019-12-07 08:15:27
问题 I'm quite new to Powershell and I'm using the Get-Hash cmdlet: This works: PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New Folder\database.adp" -Algorithm SHA512 This fails: PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New [Folder]\database.adp" -Algorithm SHA512 Get-Hash : Cannot bind argument to parameter 'Path' because it is an empty array. I understand this is likely due to the square brackets in the path [] which are valid under windows operating systems. So how do I get

Trying to create. initialize, and format VHD disks

不问归期 提交于 2019-12-07 05:53:48
问题 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 possible, which is the following: $vms=Get-VM $val = 0 Write-Host "This script is set up for quickly creating and initilizing VHDs" $Path = Read-Host "Please enter the path you want to create the drives to. Use the formate in this example <E:\VHDS\>"

Interoping With PowerShell CmdLets

自古美人都是妖i 提交于 2019-12-07 01:43:50
问题 I've been writing some utilities that make use of PowerShell Cmdlets for App-V. The interesting part is Microsoft seems to only document the cmdlets and not the .net assemblies used behind the Powershell modules. Now I'm familiar with P/Invoke and COM Interop and I've learned how to use System.Management.Automation to create a powershell session and invoke the cmdlets. But something doesn't smell right to me. I'm basically writing my own wrapper classes to hide the powershell invocations from

Referencing a file containing square brackets ([]) in it's path

廉价感情. 提交于 2019-12-05 16:34:40
I'm quite new to Powershell and I'm using the Get-Hash cmdlet: This works: PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New Folder\database.adp" -Algorithm SHA512 This fails: PS M:\> Get-Hash -Path "C:\Users\medmondson\Desktop\New [Folder]\database.adp" -Algorithm SHA512 Get-Hash : Cannot bind argument to parameter 'Path' because it is an empty array. I understand this is likely due to the square brackets in the path [] which are valid under windows operating systems. So how do I get powershell to escape these? Try to use ` backtick to escape the square bracket and enclose the whole

Is there a way to add Alias to Powershell Cmdlet programmatically?

淺唱寂寞╮ 提交于 2019-12-05 14:41:39
I am writing custom Powershell cmdlets for my application and I need to provide Aliases to some cmdlets. So lets say I have cmdlet Get-DirectoryListing and I want to add Alias (say 'gdl') to this cmdlet. How can I do this? The AliasAttribute doesn't work here, since it works only with Properties, Indexers or Field declarations. Also I know we can use Set-Alias command, but don't know where to put it. Is it possible to programmatically add multiple aliases to a cmdlet? You need to create a psm1 file ( powershell module ) where you specific your dll with yours cmdlets to load and add aliases in

How do I move files from an old folder structure to new?

别说谁变了你拦得住时间么 提交于 2019-12-04 15:46:15
I want to modify my existing folder structure. I had a file tree that was organized in the following way: Client Name State/Province City Order Number But I have modified it to add an address before the order number separated by a hyphen, as such: Client Name State/Province City Order Number - Address I created the new folder structure with a macro I had that generated the original, and I figured this was much easier than renaming the existing folders. So now I want to upload the empty folders to my server, but before I do that I want to take the files from all the old structure and put them