Skip to main content

Powershell: Commonly used command lets

Get Things Done with Powershell. Notes on daily using Powershell.

$PSVersionTable : Get Powershell version
New-Guid
Get-Alias / gal
Get-Verb
Get-Member
Get-Item / gi
Set-Item / si
Get-ChildItem / gci

Help-Update

Get the last argument with $$

Example: Create new folder lthwpowershell, then change into that newly created folder

PS F:\Projects> New-Item -Type Directory lthwpowershell


    Directory: F:\Projects


Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        6/23/2019   2:28 PM                lthwpowershell


PS F:\Projects> Set-Location $$
PS F:\Projects\lthwpowershell>

On Linux, we use $_ instead.

Generate GUID with New-Guid

PS C:\Users\Tuyen> new-guid

Guid
----
9297476d-2357-4e5d-896b-569613b2865f


PS C:\Users\Tuyen>


Get-ADUser -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users.csv -NoTypeInformation
$currentdate = Get-Date -Format yyyyMMdd
$server = "dc.ipractice.com.vn"
$domain = "ipractice"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation
$server = "dc-pr.hanoi.ipractice.com.vn"
$domain = "hanoi"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation
$server = "dchaiphong.haiphong.ipractice.com.vn"
$domain = "haiphong"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation
$server = "dcnghean.nghean.ipractice.com.vn"
$domain = "nghean"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation
$server = "dcdanang.danang.ipractice.com.vn"
$domain = "danang"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation
$server = "dchcm.hcm.ipractice.com.vn"
$domain = "hcm"
Get-ADUser -Server $server -Filter * -Properties * | Select-Object -Property * | Export-Csv -Path C:\Audit\Users-$domain-$currentdate.csv -NoTypeInformation

Run command one by one, skip the rest if one command return false: &&

echo 1 && echo "sleep 5 seconds" && sleep 5 && echo 2

Run command in backgroud: &

sleep 10 &

Check backgroud job

job

Popular posts from this blog

Hydra: Notes

Hydra v9.1 (c) 2020 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these *** ignore laws and ethics anyway).

WinRAR command

Examples: Compress four folders f:\z1 f:\z2 f:\z3 f:\z4 to one file f:\z.rar. "c:\Program Files\WinRAR\Rar.exe" a f:\z.rar f:\z1 f:\z2 f:\z3 f:\z4 F:\>"c:\Program Files\WinRAR\Rar.exe" RAR 5.61 x64 Copyright (c) 1993-2018 Alexander Roshal 30 Sep 2018 Trial version Type 'rar -?' for help Usage: rar - - a Add files to archive c Add archive comment ch Change archive parameters cw Write archive comment to file d Delete files from archive e Extract files without archived paths f Freshen files in archive i[par]= Find string in archives k Lock archive l[t[a],b] List archive contents [technical[all], bare] m[f] Move to archive [files only] p Print file to stdout r Repair archive rc Reconstruct missing volumes rn Rename archived ...