Thursday, October 7, 2010

Powershell commands

This is an extract of what I have read here. http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-conditional-logic/

Powershell commands are called Cmdlet (Command-Let).
get-command, List all powershell commands
get-command -verb Get, List all commands starting with word Get
get-command -noun service, List all commands ending with word service
get-help get-service, Get help for a particular command i.e. get-service
remove-item c:\test.txt, Removes the specified item
get-childItem c:\zip , Get items and subitems from a specified location
get-childItem c:\zip *.txt, Get all txt files from specified location
get-date , Get current date
======== Script to add 2 days to the current day ==========
$Now = Get-Date
$LastWrite = $Now.AddDays(2)
Write-Host $LastWrite
===========================================================
======= Display full path of file and last edited date time =============
$Files  =  $Files = get-childitem c:\zip  -include *.txt -recurse
foreach ($File in $Files)
{
write-host "File Name : $File " $File.LastWriteTime
}
=========================================================================

PowerShell Comparison Operators:

Operator Description
-eq Equal to
-lt Less than
-gt Greater than
-ge Greater than or Eqaul to
-le Less than or equal to
-ne Not equal to

No comments:

Post a Comment