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
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: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 - 3/22/2025, 11:10:04 AM
Hello 2025
Hello 2025
satya - 3/22/2025, 11:18:25 AM
You can do a lot with these
- dir - do a wild card search on directory trees
- select - Select a set of columns from the output of the dir or any command
- sort - sort by any column from the previous output (via pipe)
- ....
- help - use help to ask about each of the commands above
satya - 3/22/2025, 11:19:00 AM
Example
dir *somefile* | select LastwriteTime, FullName | sort LastWriteTime -descending
satya - 3/22/2025, 12:42:44 PM
Env commands
- dir Env: #List environment
- ls Env:
- gci Env:
- ... they all same
- ...
- $env:path #value of path variable
satya - 3/22/2025, 12:50:44 PM
Using the where clause
# List environment variables whose name is related
# to python virtual environments
dir Env: | where name -Like *virtual*