-
-
Save gbargsley/ebfc25061e8241ca2973c5b74ef42a10 to your computer and use it in GitHub Desktop.
Revisions
-
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,6 +65,8 @@ Get-Command -Name *module* -Module mic*core # Which commands can Get-Module -ListAvailable # Show me all of the modules installed on my system (controlled by $env:PSModulePath) Get-Module # Show me all of the modules imported into the current session $PSModuleAutoLoadingPreference = 0 # Disable auto-loading of installed PowerShell modules, when a command is invoked Import-Module -Name NameIT # Explicitly import a module, from the specified filesystem path or name (must be present in $env:PSModulePath) Remove-Module -Name NameIT # Remove a module from the scope of the current PowerShell session -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -65,8 +65,8 @@ Get-Command -Name *module* -Module mic*core # Which commands can Get-Module -ListAvailable # Show me all of the modules installed on my system (controlled by $env:PSModulePath) Get-Module # Show me all of the modules imported into the current session Import-Module -Name NameIT # Explicitly import a module, from the specified filesystem path or name (must be present in $env:PSModulePath) Remove-Module -Name NameIT # Remove a module from the scope of the current PowerShell session New-ModuleManifest # Helper function to create a new module manifest. You can create it by hand instead. -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,10 @@ Get-Command # Retrieves a list of all the commands available to PowerShell # (native binaries in $env:PATH + cmdlets / functions from PowerShell modules) Get-Help # Get all help topics Get-Help -Name about_Variables # Get help for a specific about_* topic (aka. man page) Get-Help -Name Get-Command # Get help for a specific PowerShell function Get-Help -Name Get-Command -Parameter Module # Get help for a specific parameter on a specific command ################################################### # Flow Control Statements -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ Get-Command Get-Help ################################################### # Flow Control Statements @@ -50,7 +52,27 @@ function Do-Something { } ################################################### # Working with Modules ################################################### Get-Command -Name *module* -Module mic*core # Which commands can I use to work with modules? Get-Module -ListAvailable # Show me all of the modules installed on my system (controlled by $env:PSModulePath) Get-Module # Show me all of the modules imported into the current session Import-Module # Explicitly import a module, from the specified filesystem path or name (must be present in $env:PSModulePath) Remove-Module # Remove a module from the scope of the current PowerShell session New-ModuleManifest # Helper function to create a new module manifest. You can create it by hand instead. New-Module -Name trevor -ScriptBlock { # Create an in-memory PowerShell module (advanced users) function Add($a,$b) { $a + $b } } New-Module -Name trevor -ScriptBlock { # Create an in-memory PowerShell module, and make it visible to Get-Module (advanced users) function Add($a,$b) { $a + $b } } | Import-Module ################################################### # Module Management ################################################### Get-Command -Module PowerShellGet # Explore commands to manage PowerShell modules -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,10 +1,19 @@ ################################################### # Flow Control Statements ################################################### if (1 -eq 1) { } # Do something if 1 is equal to 1 do { 'hi' } while ($false) # Loop while a condition is true (always executes at least once) while ($false) { 'hi' } # While loops are not guaranteed to run at least once while ($true) { } # Do something indefinitely while ($true) { if (1 -eq 1) { break } } # Break out of an infinite while loop conditionally for ($i = 0; $i -le 10; $i++) { Write-Host $i } # Iterate using a for..loop foreach ($item in (Get-Process)) { } # Iterate over items in an array ################################################### # Variables ################################################### -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -51,7 +51,9 @@ Find-Module -Name ps* # Find modules in th Install-Module -Name NameIT -Scope CurrentUser -Force # Install a module to your personal directory (non-admin) Install-Module -Name NameIT -Force # Install a module to your personal directory (admin / root) Install-Module -Name NameIT -RequiredVersion 1.9.0 # Install a specific version of a module Uninstall-Module -Name NameIT # Uninstall module called "NameIT", only if it was installed via Install-Module Register-PSRepository -Name <repo> -SourceLocation <uri> # Configure a private PowerShell module registry Unregister-PSRepository -Name <repo> -SourceLocation uri # Deregister a PowerShell Repository -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,13 +5,15 @@ if (1 -eq 1) { } # Do something if 1 is equal to 1 ################################################### # Variables ################################################### $a = 0 # Initialize a variable [int] $a = 'Trevor' # Initialize a variable, with the specified type (throws an exception) [string] $a = 'Trevor' # Initialize a variable, with the specified type (doesn't throw an exception) Get-Command -Name *varia* # Get a list of commands related to variable management Get-Variable # Get an array of objects, representing the variables in the current and parent scopes -
pcgeek86 revised this gist
Feb 13, 2019 . 1 changed file with 5 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,14 +12,18 @@ $a = 0 # Variables ################################################### Get-Command -Name *varia* # Get a list of commands related to variable management Get-Variable # Get an array of objects, representing the variables in the current and parent scopes Get-Variable | ? { $PSItem.Options -contains 'constant' } # Get variables with the "Constant" option set Get-Variable | ? { $PSItem.Options -contains 'readonly' } # Get variables with the "ReadOnly" option set New-Variable -Name FirstName -Value Trevor New-Variable FirstName -Value Trevor -Option Constant # Create a constant variable, that can only be removed by restarting PowerShell New-Variable FirstName -Value Trevor -Option ReadOnly # Create a variable that can only be removed by specifying the -Force parameter on Remove-Variable Remove-Variable -Name firstname # Remove a variable, with the specified name Remove-Variable -Name firstname -Force # Remove a variable, with the specified name, that has the "ReadOnly" option set ################################################### # Functions -
pcgeek86 created this gist
Feb 13, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ ################################################### # Conditional Statements ################################################### if (1 -eq 1) { } # Do something if 1 is equal to 1 $a = 0 ################################################### # Variables ################################################### Get-Variable # Get an array of objects, representing the variables in the current scope New-Variable -Name FirstName -Value Trevor New-Variable FirstName -Value Trevor -Option Constant # Create a constant variable, that can only be removed by restarting PowerShell New-Variable FirstName -Value Trevor -Option ReadOnly # Create a variable that can only be removed by specifying the -Force parameter on Remove-Variable Remove-Variable -Name firstname # Remove a variable, with the specified name ################################################### # Functions ################################################### # A PowerShell Advanced Function, with all three blocks declared: BEGIN, PROCESS, END function Do-Something { [CmdletBinding]()] param () begin { } process { } end { } } ################################################### # Modules ################################################### Get-Command -Module PowerShellGet # Explore commands to manage PowerShell modules Find-Module -Tag cloud # Find modules in the PowerShell Gallery with a "cloud" tag Find-Module -Name ps* # Find modules in the PowerShell Gallery whose name starts with "PS" Install-Module -Name NameIT -Scope CurrentUser -Force # Install a module to your personal directory (non-admin) Install-Module -Name NameIT -Force # Install a module to your personal directory (admin / root) Uninstall-Module -Name NameIT # Uninstall module called "NameIT", only if it was installed via PowerShell Gallery Register-PSRepository -Name <repo> -SourceLocation <uri> # Configure a private PowerShell module registry