question

dantenan avatar image
dantenan asked

Cmdlets using Powershell

Hi Guys, Anyone worked on writting cmdlets uisng powershell?
powershell
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

What are you trying to accomplish? There are tons of examples on the internet on how to write your own custom cmdlet.
0 Likes 0 ·
I am trying to write a cmdlet in powershell for a cluster(Storage) . I need to write a cmdlet for all the major functionalities perfomred in the ui. For example: I need to develop a cmdlet to connect to a Storage cluster. i have been given a yaml file by the client, I have generated the powershell sdk using swagger tool. Below are the list of cmdlets i need to develop Cohesity-Connect : Connect to Cohesity Cluster Cohesity-ListDataProtectionJobs Cohesity-ListPolicies Cohesity-CreatePolicies Cohesity-CreateDataProtectionJobs Cohesity-PauseDataProtectionJobs Request you to provide your inputs for developing these cmdlets.
0 Likes 0 ·
dantenan avatar image
dantenan answered
Attached is the generated sdk file
8 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Is this continuing from your question? Or is it an answer to your question?
0 Likes 0 ·
Hi Thomas yes, it is the continuation of the question. The attached is the generated Powershell SDK using swagger tool. My first actual requirement is to connect to the storage cluster using cmdlet. The name of the cmdlet should be Cohesity-Connect. Thanks and Regards
0 Likes 0 ·
Just curious, have you contacted Cohesity yet? Most storage vendors today offer up powershell cmdlets to help facilitate things.
0 Likes 0 ·
Hi John, Actually there is another client called Nutanix, which also runs by the people involved with cohesity. Nutanix has developed similar cmdlets for Nutanix clusters. So now the requirement is Cohesity also wants to develop cmdlets for there clusters. Thanks and Regards,
0 Likes 0 ·
And you think a SQL Server focused Q&A site is the place to ask? This feels more and more as though you're trying to get us to do your homework. Or, worse, your day job. Or something that you've promised to a client and you're now being asked when you'll have it ready.
0 Likes 0 ·
Hi Thomas, Actually I have seen few posts about powershell in this site, So thats the reason I have posted it. I hoped i may gather some information. any way no problem thanks for your time. Thanks and Regards
0 Likes 0 ·
I've removed the attached .rar file - are you able to post your CMDlet as code instead?
0 Likes 0 ·
Below is the api for connecting to Cluster function New-AccessTokenCredential { [CmdletBinding()] Param ( [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true)] [String] ${domain}, [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] [String] ${password}, [Parameter(Position = 0, ValueFromPipelineByPropertyName = $true, Mandatory = $true)] [String] ${username} ) Process { 'Creating object: IO.Swagger.Model.AccessTokenCredential' | Write-Verbose $PSBoundParameters | Out-DebugParameter | Write-Debug New-Object -TypeName IO.Swagger.Model.AccessTokenCredential -ArgumentList @( ${domain}, ${password}, ${username} ) } }
0 Likes 0 ·
Shawn_Melton avatar image
Shawn_Melton answered

Clarification on terms but a cmdlet (command-let) is a command in PowerShell tied to a DLL. So if you are writing that then you would be writing C# and compiling the DLL file. All of the code executed by the `Verb-Noun` command in PowerShell is in that DLL file. This is how many of the commands in the `sqlserver` module are written.

A function is a collection of PowerShell commands (e.g. `Get-Service`, `Get-CimInstance`, etc.) that you can manipulate just by opening it in a text editor.

If you want to develop commands for manipulating or managing a storage cluster, just write out the common task you would normally do and then expand that to include inputs and outputs. You wrap that into a function and you are done. One thing to note is make sure you are using approved verbs if you plan on developing this into a module to share. (Otherwise PowerShell will spit out warnings everytime you import the module).

10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.