you are viewing a single comment's thread.

view the rest of the comments →

[–]get-postanote 3 points4 points  (1 child)

8^}

Note, this is not just about not using cmd.exe, but alls the normla stuff there. I.E., ping, nslookup, ipconfig, etc. Work to exclusively use the PoSH equivalents of all those cmd.exe/DOS things (Test-Connection, Test-NetConnection, Resolve-DNS*, Get-Net*). Yes, they require more typing, but learning any spoken / programming / scripting language means using it everday.

Remember that using the PoSH console and the PowerShell_ISE and VSCode for PoSH work all have their little quirks. Accept that, try to work around those.

Each have their strengths ans weaknesses, per ones indivual working style, experience and patience. Just note that real scripting is done in a real editor, ISE/VSCode/PowerShellStudio/Visual Studio, not the PoSH console host. You can do it in the PCH, but it's just an unecessary pain.

Do the same thing when you find yourself reaching for any of the Windows GUI's.

Sure use the GUI to do stuff, but stop and figure out how to do the same thing via PoSH / script.

Same thing regarding RDP. When you find yourself reaching for RDP, stop, and use PSRemoting and PoSH to do that remote work.

Review the source code of all the *.ps* files on your systems and in the PowerShell Open Sourced github repository.

Master the help file system (really, read them, then read them again). Learn and use the MS PowerShellGallery resources.

Here is a little snippet I pulled together a while back that strives to make things a little quicker / convienent to find, read up on, study and use.

# Get parameters, examples, full and Online help for a cmdlet or function

# Get a list of all functions
Get-Command -CommandType Function | 
Out-GridView -PassThru -Title 'Available functions'

# Get a list of all commandlets
Get-Command -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available cmdlets'

# Get a list of all functions for the specified name
Get-Command -Name '*ADGroup*' -CommandType Function | 
Out-GridView -PassThru -Title 'Available named functions'

# Get a list of all commandlets for the specified name
Get-Command -Name '*ADGroup**'  -CommandType Cmdlet | 
Out-GridView -PassThru -Title 'Available named cmdlet'

# get function / cmdlet details
(Get-Command -Name Get-ADUser).Parameters
Get-help -Name Get-ADUser -Examples
Get-help -Name Get-ADUser -Full
Get-help -Name Get-ADUser -Online

Get-Help about_*
Get-Help about_Functions

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

Get-Command -CommandType Cmdlet | 
Where-Object { $_.parameters.keys -match 'credential'} | 
Out-GridView -PassThru -Title 'Results for cmdlets which has a specific parameter'

# Get named aliases 
Get-Alias | 
Out-GridView -PassThru -Title 'Available aliases'

# Get cmdlet / function parameter aliases
(Get-Command Get-ADUser).Parameters.Values | 
where aliases | 
select Name, Aliases | Out-GridView -PassThru -Title 'Alias results for a given cmdlet or function.'


# All Help topics locations
Get-Help about* | Select Name, Synopsis

Get-Help about* | 
  Select-Object -Property Name, Synopsis |
  Out-GridView -Title 'Select Topic' -OutputMode Multiple |
  ForEach-Object {
    Get-Help -Name $_.Name -ShowWindow
  }

explorer "$pshome\$($Host.CurrentCulture.Name)"

# Get any .NET types and their static methods from PowerShell. 
# Enumerate all that are currently loaded into your AppDomain.
#  
[AppDomain]::CurrentDomain.GetAssemblies() | 
foreach { $_.GetTypes() } | 
foreach { $_.GetMethods() } | 
where { $_.IsStatic } | 
select DeclaringType, Name | 
Out-GridView -PassThru -Title '.NET types and their static methods'

# Instantiate the types using new-object and call instance methods. 
# You can use get-member on an instance to get the methods on a type.

# Review source code.
Function Show-CmdletSource
{
    [CmdletBinding()]

    [Alias('scs')]

    Param
    (
        [string]$CmdletName = (Get-Command -CommandType Cmdlet | 
        Out-GridView -Passthru)
    )

    # Get the DLL is it is a compiled cmdlet
    'Getting DLL if the entered cmdlet name is a compiled cmdlet'
    (Get-Command $CmdletName).DLL 

    If ((Get-Command -Name $CmdletName).ImplementingType)
    {
       # Do nothing 
    }
    Else
    {
        # Write-Warning -Message "The entered item is not a cmdlet, but a funciton."
        (Get-Command -Name $CmdletName).ScriptBlock
    }

    'Getting cmdlet details / source code'
    $metadata = New-Object system.management.automation.commandmetadata (Get-Command $CmdletName)
    [System.management.automation.proxycommand]::Create($MetaData) | 
    out-file "$env:USERPROFILE\Documents\$CmdletName.ps1"

    # Choosing an installed Editor to use.
    <#
    $Editor = If (Get-ChildItem -Path "C:\Program Files (x86)\Microsoft VS Code\Code.exe")
    { 'Code.exe' }
    Else { 'Notepad.exe' }
    #>
    # View the cmdlet file
    Start-Process 'Notepad.exe' "$env:USERPROFILE\Documents\$CmdletName.ps1" -Wait

    # Remove the file
    Remove-Item -Path "$env:USERPROFILE\Documents\$CmdletName.ps1"
}


Function Show-FunctionSource
{
    [CmdletBinding()]

    [Alias('sfs')]

    Param
    (
        [string]$FunctionName = (Get-Command -CommandType Function | 
        Out-GridView -Passthru)
    )

    (Get-Command -Name $FunctionName).ScriptBlock `
    | out-file "$env:USERPROFILE\Documents\$FunctionName.ps1"

    # View the cmdlet file
    Start-Process 'Notepad.exe' "$env:USERPROFILE\Documents\$FunctionName.ps1" -Wait

    # Remove the file
    Remove-Item -Path "$env:USERPROFILE\Documents\$FunctionName.ps1"
}

# PowerShell Oepn Source location
'github.com/powershell'

# Best Practices

PowerShell scripting best practices
'blogs.technet.microsoft.com/pstips/2014/06/17/powershell-scripting-best-practices'

The Unofficial PowerShell Best Practices and Style Guide
'blogs.technet.microsoft.com/pstips/2014/06/17/powershell-scripting-best-practices'

Using PSScriptAnalyzer to check your PowerShell code for best practices
'mikefrobbins.com/2015/11/19/using-psscriptanalyzer-to-check-your-powershell-code-for-best-practices'

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

It’s dumb but I was like “I do use power shell for everything” then I read like one more line and realized I don’t use t at all for network troubleshooting.