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

Free online resources to practice

Photo Credit:  johnhain  - pixabay.com There are many free online resources for us to practice almost any or specific skills as long as we have an Internet connection.

Qubes OS: Fedora 30

Create a new Standalone VM based on fedora-29 VM template Extend root partition: run command on dom0 tuyen@dom0:~ $ qvm-volume extend fedora-30:root 12288MB Set qrexec_timeout to 600 seconds tuyen@dom0:~ $ qvm-pref --set fedora-30 qrexec_timeout 600 $ sudo dnf upgrade --refresh $ sudo dnf install dnf-plugin-sytem-upgrade $ sudo dnf system-upgrade download --release=30 Install fedora-30 template Run the following command on dom0 terminal $ sudo qubes-dom0-update qubes-template-fedora-30 Install Adobe Flash Player Adobe Flash Player will not go away soon. So, let's grab the latest version of Adobe Flash Player , then install using yum or dnf command. Verify if Adobe Flash Player is installed and works by visiting https://helpx.adobe.com/flash-player.html [user@fedora-30 ~]$ sudo dnf install Downloads/flash-player-npapi-32.0.0.238-release.x86_64.rpm Last metadata expiration check: 0:37:03 ago on Fri Aug 30 09:18:10 2019. Dependencies resolved. =========...

Check free space with disk free and disk usage

df -h -h: display result in KB, MB, GB Check free disk with disk free (df)