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

IBM Domino: How to enable HTTP Request logging in Domino

http://www-01.ibm.com/support/docview.wss?uid=swg21099151 Technote (FAQ) Question How do you enable HTTP request logging when using a Lotus® Domino® Web server? You want a record of all requests sent by Web browsers to the Domino server to use for troubleshooting. Answer Below is a short guide to turning on request logging that provides the basic logging level. More verbose logging can be enabled by following the instructions in  "Overview of HTTP Request Logs" (#7003598) . Important:  HTTP request logging should be used only for troubleshooting specific issues, and usually at the direction of and with assistance from IBM Support. Do not use request logging for other purposes, such as administrative reasons. Because these log files grow in size over time, you should not leave this setting enabled for long periods or you will exhaust the available drive space. To enable logging of HTTP requests for a Domino server for the current HTTP session only, enter the f...

Windows Command: arp - Address Resolution Protocol

Notes from daily work situation. While troubleshooting HSRP, I need to delete arp table on my computer. arp -d * Take a look at other options with arp command: C:\Users\Administrator>arp /? Displays and modifies the IP-to-Physical address translation tables used by address resolution protocol (ARP). ARP -s inet_addr eth_addr [if_addr] ARP -d inet_addr [if_addr] ARP -a [inet_addr] [-N if_addr] [-v] -a Displays current ARP entries by interrogating the current protocol data. If inet_addr is specified, the IP and Physical addresses for only the specified computer are displayed. If more than one network interface uses ARP, entries for each ARP table are displayed. -g Same as -a. -v Displays current ARP entries in verbose mode. All invalid entries and entries on the loop-back interface will be shown. inet_addr Specifies an internet address. -N if_a...

Microsoft Windows Server 2012 R2 Standard Evaluation Product Key

Microsoft Windows Server 2012 R2 Standard Evaluation D2N9P-3P6X9-2R39C-7RTCD-MDVJX DBGBW-NPF86-BJVTX-K3WKJ-MTB6V