Skip to content

Latest commit

 

History

History
144 lines (130 loc) · 3.66 KB

USERGUIDE.md

File metadata and controls

144 lines (130 loc) · 3.66 KB

BASH Equivalents

BASH Powershell
cat $file | less gci $filename | more
CMD | less CMDLET | more
CMD | grep CMDLET | findstr
CMDLET | out-string -stream | sls
Note: *sls* is Select-String

Commands / Aliases

Get-ChildItem gci
ls
dir
Remove-Item ri
rm
rmdir
del
erase
rd
Get-Command gcm
_(just like *which* in Bash)_
Get-Content gc
cat
type
New-Item ni
Get-Member gm
echoecho
write-host
write-verbose
write-debug

Environment Variables

List

  • ls env:
  • ls env:U*

Echo / Print

  • echo $env:userprofile

Create / Modify

  • Per Session
    • $env:myvar = "abc123"
  • Permanent
    • [Environment]::SetEnvironmentVariable( "Name", "Value", "<OPTION>" )
      • where OPTION is one of:
        • User (per use profile)
        • Machine (anyone logged into the machine)
        • Process (temporary, for this session only, same as $env syntax above)

Delete / Unset

  • remove-item Env:$myvariable
  • [Environment]::SetEnvironmentVariable( "Name", $null, "<OPTION>" )

Splatting

Break long commands into readable chunks by specifying parameters in a hash.

$params = @{ 'class' = 'Win32_BIOS';
             'computername'='SERVER-R2';
             'filter'='drivetype=3';
             'credential'='Administrator' }

Get-WmiObject @params

Proxy Functions

Create useful aliases (like in Bash) that pass cmdline parameters onto the underlying command

function vbox { vagrant box @Args }

References

Custom Profiles

Directory Locations
Per User $USERPROFLE\Documents\WindowsPowerShell\
All users $windir\system32\WindowsPowerShell\v1.0\
Special File Names (must be in one of the directories above)
Global profile.ps1
Powershell Only Microsoft.PowerShell_profile.ps1

References

Symbolic Links

  • New-Item -ItemType SymbolicLink -Name <SRC> -Target <TGT>
  • New-Item -itemtype junction -name <SRC> -target <TGT>

References

Getting Help

  • man <cmdlet>
  • <cmdlet> -?
  • get-help [-detailed -full -parameter <param-name> -examples]

Get the Type of something

  • GetType()
  • Example: (get-date).getType()

Get the properties of something

  • Get-Member
  • Alias: gm
  • Example: ( get-date ).DayOfWeek | gm -f

Debugging

Set-PSDebug -Trace 1