Powershell on the command line

satya - 9/19/2020, 9:43:05 AM

There are multiple aspects to powershell

1. how it is used on the command line

2. how it is used for programming and scripting work

3. (likely) how it is used in the cloud like azure

satya - 9/19/2020, 9:43:32 AM

These notes are for command line

These notes are for command line

satya - 9/19/2020, 9:45:25 AM

Example


# file array
$x = dir 

# first entry
$x1 = $x[0]

# find its type
$x1 | Get-type

# find the methods
$x1 | Get-Member

satya - 9/19/2020, 9:47:40 AM

Files changed since....


# Get all file (objects) recursively
dir *.sql -Recurse

# Select that have changed since
dir *.sql -Recurse | where -Property CreationTime -gt '9/1/2020'

#note the time format is locale sensitive

satya - 9/19/2020, 9:53:24 AM

This link on commandlets in powershell could be useful

This link on commandlets in powershell could be useful

satya - 1/14/2022, 4:19:06 PM

How do I exit or quit powershell

1. Use "exit" at the command line to quit

2. To start a powershell use the windows search icon to look for "powershell"

satya - 1/14/2022, 4:33:02 PM

Here is how you do a quick (or long) grep



#The following will give you the attributes
get-alias | get-member

#Then you can chose the objects 
#whose attribute matches to what you like
get-alias | Where-Object -Property ReferencedCommand -Like "*var*"

satya - 1/14/2022, 4:34:52 PM

Some useful commands


Get-Variables - Global variables such as version number etc.
Get-Module - Show modules
Get-Command - Show commandlets in a module
Get-Help
Get-Help -examples
Get-Member - Show me the attributes of an object
Select-Object First
Get-alias - Show aliases
Get-PSProviders - show drives
Get-ComputerInfo

satya - 1/15/2022, 11:30:19 AM

Another useful command: Measure-Object

You have things like

min

max

average

etc....

satya - 1/15/2022, 11:40:21 AM

And anothr: Get-PsRepoistory


Lists registered public repos
PS C:\satya\data\code\power-shell> Get-PSRepository

Name        InstallationPolicy   SourceLocation
----        ------------------   --------------
PSGallery   Untrusted            https://www.powershellgallery.com/api/v2

satya - 1/15/2022, 11:47:34 AM

Module for MS Teams

Module for MS Teams

satya - 1/15/2022, 11:48:45 AM

Create a new chat with MS Teams Powershell module

Create a new chat with MS Teams Powershell module

Search for: Create a new chat with MS Teams Powershell module

satya - 1/15/2022, 11:49:04 AM

MS Docs: Powershell for MS Teams

MS Docs: Powershell for MS Teams