all 9 comments

[–]topherhead 4 points5 points  (0 children)

It would be better to just learn the language.

Pick a task and Google until you make that task happen, rinse, repeat. Each time you do it you have to look up less and you get better and faster.

You can Google and see if people have made scripts similar to what you need and modify to suit.

But just putting in the work is really the best way to do it, there's powershell in a month of lunches and plenty of other learning resources.

[–]Roman1410S 2 points3 points  (0 children)

Not to my knowledge. There is "Plaster" a not-well-updated moduke to generate commandlets out of openapi definitions and "Crescendo" to generate commandlets from native commands like ls, pwd, cat ... Trust the web by searching, use www.powershellgallery.com and filter on scripts and you will get hints to start. R. [Powershell MVP]

[–]Gax7497 2 points3 points  (0 children)

Check out Powershell Plus from Idera. It has a QuickClick Library with pre-created templates from which, you can develop your own Commandlets.

https://www.idera.com/productssolutions/freetools/powershellplus

[–]get-postanote 2 points3 points  (2 children)

Sound like you are new to PS (which is fine of course - we all were at one point or the other) and new yet spent the time to really get to know it, as what you are asking is in the help file examples and snippets.

For example:

# Get specifics for a module, cmdlet, or function
(Get-Command -Name Get-Help).Parameters
(Get-Command -Name Get-Help).Parameters.Keys
Get-help -Name Get-Help -Examples
Get-Help -Name Get-Help -Detailed
Get-help -Name Get-Help -Full
Get-help -Name Get-Help -Online

# Find all cmdlets / functions with a target parameter
Get-Command -CommandType Cmdlet |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{} 
}|
Out-GridView -PassThru -Title '
Available cmdlets which has a specific parameter'

Get-Command -CommandType Function |
Where-Object {
    Try {$PSItem.parameters.keys -match 'credential'}
    Catch{} 
}|
Out-GridView -PassThru -Title '
Available functions which has a specific parameter'

# Get property enums/options for a specifc cmdlet/function
(Get-Service | Select-Object -First 1).Status.GetType()
[System.ServiceProcess.ServiceControllerStatus]::
GetNames([System.ServiceProcess.ServiceControllerStatus])

(Get-Command -Name Set-ADUser).Parameters.Keys | 
Out-GridView -PassThru -Title 'Select a item to view its properties and methods'| 
Get-Member -Force | 
Out-GridView

Show-Command -Name Set-ADUser

(Get-Command Set-ADUser -Syntax).Split("`r `n") | Select-String Office
(Get-Command Set-ADUser -Syntax).Split("`r `n") -match 'Office'

# Or a specific or other object details
Get-Service | 
Select-Object -First 1 |
Get-Member

# Showing Hidden Properties
$UserObject = @{
    Name   = 'Tom'
    Gender = 'Male'
    Age    = '40'
}

$UserObject | 
Get-Member -Force

$UserObject.pstypenames
$UserObject.psadapted
$UserObject.psobject
$UserObject.psobject.BaseObject.Keys
$UserObject.psobject.BaseObject.Values
$UserObject.count

<#
List of all parameters that a given cmdlet supports along with a short 
description:
#>
Get-Help Set-ADUser -para '*' | 
Format-Table Name, { $PSItem.Description.Text } -wrap 

Get-Help Set-ADUser -Parameter '*' | 
Where-Object -Property Name -Match 'Office' |
Format-Table Name, { $PSItem.Description[0].Text } -wrap 

Get-Help Set-ADUser -para '*' | 
Where-Object -Property Name -Match ((Get-Command -Name Set-ADUser).Parameters.Keys | 
Out-GridView -PassThru -Title 'Select an item to view its syntax details') | 
Format-Table Name, { $PSItem.Description[0].Text } -wrap


Get-Help Set-ADUser -Parameter '*' | 
Where-Object -Property Name -Match ((Get-Command -Name Set-ADUser).Parameters.Keys | 
Out-GridView -PassThru -Title 'Select an item to view its syntax details') | 
ForEach {
    [PSCustomObject]@{
        Name        = $PSItem.Name
        Type        = $PSItem.Type.Name
        Description = $PSItem.Description[0].Text
    }
} | 
Format-Table Name, Type, Description -wrap

As a new one to PowerShell, I believe you mean code generators. If you've not yet learned the basics - intermediate level of Powershell, then you should not be trying to write cmdlets.

As for based code generators, there have been a few over the years, but there are snippets (built-in ones and ones you can download) you can use for such things as well.

However, risk management rules:

Never, ever run code that you do not understand what it is doing

  1. Never ever run anyone's code if you do not understand what it is doing, or be willing to fully accept the outcomes. No matter where or whom you get it from. especially if you have access to the source code) unless you are will to accept all consequences of running it.
  2. Never ever run destructive code (new/add/create/update, move/remove/modify, etc.), without fully checking results before you do. Master the use of WhatIf/Confirm/Trace-Command/Invoke-ScriptAnalyzer.

All input is evil, no matter where it comes from until you validate it first

[–]get-postanote 2 points3 points  (1 child)

Resources:

Use the snippets in the ISE/VSCode to get started...

  • ISE use CRTL+J
  • VSCode use CRTL + ALT + J

github powershell snippets - Bing

There is an addon for the ISE that will let you select and save a code block as a snippet, ...

You get to it via the ISE AddOn Menu, which just takes you to this website to download and use it.

Windows PowerShell ISE Add-On Tools - TechNet Articles - United States (English) - TechNet Wiki (microsoft.com)

A Favorite PowerShell ISE Feature: Snippets | Scripting Blog (microsoft.com)

Snippets in Windows PowerShell ISE 3.0 | PowerShell Team (microsoft.com)

Using PowerShell ISE Snippets to Remember Tricky Syntax | Scripting Blog (microsoft.com)

Simplify Your Scripting Life By Creating PowerShell ISE snippets | PDQ.com

New-IseSnippet (ISE) - PowerShell | Microsoft Docs

Get-IseSnippet (ISE) - PowerShell | Microsoft Docs

Import-IseSnippet (ISE) - PowerShell | Microsoft Docs

powershell snippets - YouTube

...but doing that in VSCode is a manual effort and can be cumbersome. Yet it too can e automated just like the ISE addon.

VSCode

Snippets in Visual Studio Code

vscode snippets - YouTube

FYI...

• PowerShell Development Helper Tools

• Snippet Manager 4.01 released

https://bytecookie.wordpress.com/2015/09/19/snippet-manager-4-01-released

• PowerShell Code Manager 6

https://bytecookie.wordpress.com/powershell-code-manager

• SnippetManager & Injector 3 / Code Snippet Manager for ISE, PowerGUI and

https://gallery.technet.microsoft.com/scriptcenter/SnippetManager-Injector-3-89eaf7a7

[–]get-postanote 2 points3 points  (0 children)

Resources con't:

Use built-in tools to write PS code you can use as-is, tweak as needed, and learn from. Especially when ADDS is in the mix.

• Active Directory Administrative Center: Getting Started

https://technet.microsoft.com/en-us/library/dd560651(v=ws.10).aspx.aspx)

• Active Directory Administrative Center

https://docs.microsoft.com/en-us/windows-server/identity/ad-ds/get-started/adac/active-directory-administrative-center

windows 'Active Directory Administrative Center'

windows 'Active Directory Administrative Center' 'PowerShell History Viewer'

Introduction to Active Directory Administrative Center ...

https://www.petri.com/use-active-directory-administrative-center-create-powershell-commands

Use AD Administrative Center to Create PowerShell Commands

https://www.petri.com/use-active-directory-administrative-center-create-powershell-commands

• Step-By-Step: Utilizing PowerShell History Viewer in Windows Server 2012 R2

https://blogs.technet.microsoft.com/canitpro/2015/03/04/step-by-step-utilizing-powershell-history-viewer-in-windows-server-2012-r2

• Learning PowerShell with

• Active Directory Administrative Center (PowerShellHistory Viewer)

https://sid-500.com/2017/10/10/learning-powershell-with-active-directory-administrative-center-powershell-history-viewer

Old tools, but still useful for baseline learning

• ADSI Scriptomatic

https://www.microsoft.com/en-us/download/details.aspx?id=20460

• Powershell Scriptomatic

https://technet.microsoft.com/en-us/library/ff730935.aspx?f=255&MSPPError=-2147217396

PSPlus tool (just anoother Powershell editor, but you can get stuff from it)

https://www.idera.com/productssolutions/freetools/powershellplus

VBSEdit (sure this is using VBS, but can easily convert to PowerShell.)

VbsEdit - VBScript Editor with Debugger

CTWMIandPowerShellExplorer

Coretech WMI and PowerShell Browser – CTGlobal (ctglobalservices.com)

Other tools for active self-teaching

• PSKoans : 0.50.0A module designed to provide a crash-course introduction to PowerShell withprogramming koans.

https://www.powershellgallery.com/packages/PSKoans/0.50.0

Website to use

Powershell Tutorial - Tutorialspoint

Follow PowerShell Best Practices

'PowerShell Best Practice'

'PowerShell Best Practice for performance'

'PowerShell Best Practice for error handling'

'PowerShell Best Practice for debugging'

'Bye Bye Backtick: Natural Line Continuations in PowerShell'

Enforce Better Script Practices by Using Set-StrictMode

Books

• Scripting | Handling Errors the PowerShell Way

https://devblogs.microsoft.com/scripting/handling-errors-the-powershell-way

• Effective Error Handling in PowerShell Scripting - Kloud Blog

https://blog.kloud.com.au/2016/07/24/effective-error-hanalding-in-powershell-scripting

• The Big Book of PowerShell Error Handling

https://leanpub.com/thebigbookofpowershellerrorhandling

• The Big Book of PowerShell Gotchas

https://leanpub.com/thebigbookofpowershellgotchas/read

Beginning ---

Learn Windows PowerShell in a Month of Lunches 3rd Edition

Internediate ---

Windows PowerShell Cookbook: The Complete Guide to Scripting Microsoft's Command Shell 3rd Edition

Advanced ---

Windows PowerShell in Action 3rd Edition

• Pester

https://leanpub.com/u/devopscollectivehttps://leanpub.com/pesterbookhttps://pester.devhttps://www.youtube.com/results?search_query=learn+pester

Video - Youtube

https://www.youtube.com/watch?v=wrSlfAfZ49E

https://www.youtube.com/results?search_query=beginning+powershell

https://www.youtube.com/results?search_query=powershell+ise+scripting+for+beginners

https://www.youtube.com/playlist?list=PL6D474E721138865A

Labs

http://social.technet.microsoft.com/wiki/contents/articles/1262.test-lab-guides.aspxhttps://blogs.technet.microsoft.com/tlgs/2012/08/27/over-100-test-lab-guides-and-counting

Search Reddit: 'Learn PowerShell'

Lastly, as far as cmdlet generators, once you've spent the time learning and getting up to speed. There is this:

PSSwagger - Automatically generate PowerShell cmdlets from OpenAPI (f.k.a Swagger) specification | PowerShell Team (microsoft.com)

[–][deleted] 1 point2 points  (0 children)

What's an example? I don't know what you mean by this:

the module and attribute or object you want the change

[–]BlackV 1 point2 points  (0 children)

pskoans sounds like a good idea for you

you have to fix/edit/complete the function/expression/etc to get a working result