Demo-PSBasics.ps1


<#PSScriptInfo
 
.VERSION 1.0.0
 
.GUID 13a0c89a-a349-4d54-a241-461b3d401799
 
.AUTHOR Frits van Drie (3-Link.nl)
 
.COMPANYNAME 3-Link Opleidingen
 
.COPYRIGHT free to use and distribute without modifications
 
.TAGS
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
.PRIVATEDATA
 
#>
 



<#
 
.DESCRIPTION
Developed by 3-Link Opleidingen for training purposes only
 
#>
 

Param()


# File: Demo-PSBasics
# Author Frits van Drie (3-Link.nl)
# Date: 2022-04-11

Write-Warning 'This script is developed for demonstration. Open it in your code editor and run in step-by-step'
BREAK

dir 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe'
dir 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell_ISE.exe'


$PSVersionTable

# PS 7
cmd.exe /k "`"C:\Program Files\PowerShell\7\pwsh.exe`" -WorkingDirectory ~"


# Windows Terminal app (Windows 11: present / Windows 10: download from Store)
# Visual Studio Code (https://code.visualstudio.com/Download)


# Script Editor

# comment

<#
Comment block
 
Syntax Cmdlets: <verb>-<noun>
 
Syntax:
    Object-oriented:
 
 
#>


#region: Verbs and Nouns
    # GET: Read only
    Get-Service  # Retrieve services
    Get-Process
    Get-LocalUser
    Get-AzureADUser


    # SET: Modify an existing object
    Set-Service


    # Add
    Add-LocalGroupMember


    # Remove
    Remove-Item


    # NEW
    New-LocalGroup


    # Invoke
    Invoke-Command

    # Out
    Out-File
    Out-GridView


    # Export
    Export-Csv

    # ConvertTo
    ConvertTo-Json


#endregion

#region: Modules

    Install-Module
    Import-Module

    Get-Module
    Get-Module -ListAvailable

    # ModulePath
    $env:PSModulePath
    # PS 5.1
        <#
        $env:USERPROFILE\Documents\WindowsPowerShell\Modules;
        C:\Program Files\WindowsPowerShell\Modules;
        C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
        #>


    # PS7.2:
        <#
        $env:USERPROFILE\Documents\PowerShell\Modules;
        C:\Program Files\PowerShell\Modules;
        c:\program files\powershell\7\Modules;
        C:\Program Files\WindowsPowerShell\Modules;
        C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
        #>


    Get-Module ActiveDirectory
    Get-Command -Module ActiveDirectory
    Get-Command -Module AzureAD

    Get-Command -Module 3LToolKit


#endregion

#region: Help

    Get-Help Get-Help
    Get-Help Get-Service
    Get-Help Get-Service -Full
    Get-Help Get-Service -Examples
    Help Get-Service     -ShowWindow
    Help Get-Service     -Online

    help about*
    help about_Command_Syntax -ShowWindow
    help about_Comparison_Operators -ShowWindow


#endregion

#region: Get-Command
    Get-Command
    Get-Command -verb get
    Get-Command set-*adapter
    Get-Command *service

    Get-Command Get-LocalUser
    Get-Command Get-AzureADUser
    Get-Command Get-ADUser
    Get-Command Get-ADComputer


#endregion

#region: Alias

    cd \users
    cd \\dc1\Scripts
    chdir \windows
    Set-Location 'C:\Program Files'
    sl .\WindowsPowerShell


    Set-Location C:\Windows
    dir
    ls
    Get-ChildItem
    gci


    Get-Alias cd
    Get-Alias gci

    Get-Alias -Definition Get-Service

    # alias of Get-Command ?
    # alias of Get-Process ?
    # alias of Invoke-Expression ?
    Get-Alias -Definition Get-Command, Get-Process, Invoke-Expression


    New-Alias -Name goto -Value Set-Location
    Get-Alias -Definition Set-Location
    goto C:\Windows



#endregion

#region: Parameters

    # syntax: Cmdlet -ParameterName Value -ParameterName Value ...

    Get-Service -Name spooler
    Get-Service -Name spooler Bits
    Get-Service -Name spooler, Bits
    Get-Service -Name sp*
    Get-Service spooler, bits


    Get-Service -ComputerName DC1
    Get-Service -ComputerName LON-*
    Get-Service -ComputerName DC1, SVR1, localhost
    Get-Service -Name spooler -ComputerName DC1, SVR1, localhost

    Get-Service spooler -ComputerName DC1, SVR1, localhost

    Get-Service -Name spooler DC1, SVR1, localhost
    
    # Get-Service [ [-Name] <string[] ] [ -ComputerName <string[]> ]

    Get-Help Get-Service -ShowWindow  # compare syntax




#endregion

#region: Variables

    $var1 = 'abc'
    $var1

    Start-Service spooler
    $svc = Get-Service spooler
    Stop-Service spooler
    Get-Service spooler
    $svc

    Get-Variable
    Get-Variable -Name svc
    $svc = $null
    $svc = $empty
    $svc = ''

    Get-Variable -Name svc
    Remove-Variable svc
    Get-Variable -Name svc

#endregion