bash:
/home/coffee> echo “This is the `date`”
This is the Thu Mar 4 10:16:33 CST 2010
powershell:
“This is the $(Get-Date)”
This is the 03/04/2010 10:34:41
bash:
/home/coffee> echo “This is the `date`”
This is the Thu Mar 4 10:16:33 CST 2010
powershell:
“This is the $(Get-Date)”
This is the 03/04/2010 10:34:41
http://msdn.microsoft.com/en-us/cc539972.aspx Rebuilding MSDN with Angle Brackets. Pt. 1
http://msdn.microsoft.com/en-us/magazine/cc163729.aspx Scheme is Love, Don Box
http://www.microsoft.com/downloads/details.aspx?FamilyId=0724B007-D1E7-4D86-B929-BDC6BA1FC810&displaylang=en SOAP – Service-Oriented Architecture and Programming, Pt. 1
http://www.viveksharma.com/TECHLOG/archive/2006/08/05/updated-powershell-script-editing-mode-for-emacs-powershell-modeel.aspx
#Setup & Send our Mail $SmtpClient = new-object Net.Mail.SmtpClient("smtp.host.com") #Message formatting $MailMessage = New-Object system.net.mail.MailMessage $MailMessage.From = "The Farm Hand <chicken_counter@professionalvmware.com>" $MailMessage.To.add("john@fromthebrink.org") $MailMessage.Subject = "Direct from your local VC: Weekly Statistics" $MailMessage.Priority = "high" #Build Body $Body += "line one" $Body += "line two” $Body += "line three” $MailMessage.Body = $Body #Send message $SmtpClient.Send($MailMessage)
Since powershell is trying to do so much under the covers, it can get silly at times. When you have many thousand files in a directory, (which is a silly idea to begin with) powershell slows down to a crawl when the dir command bundled in ‘cmd.com’ still works great. The easiest answer is to simply use that command instead, break you data into smaller chunks, and then powershell-ize your data after the fact. If you don’t do this, you could really screw yourself when your powershell script appears to run slowly or stop completely.
<pre>
cmd /c dir
</pre>
This will run the old dir command from cmd.com for you from powershell. But what if cmd.com goes away, as Microsoft promises? Either you must write a wrapper that you can replace with something other than powershell without any code change, or your must find that other command today. I am thinking of a unix port like the real ‘ls’ (not powershell alias) or ‘find’. Find suffers a similar issue in unix, but only if you give it parameters, if you just do a straight find ( find . or find -print ), everything works as it just goes one record at a time. Also, in powershell, what counts is how many files you have in one directory, or ask about from one command.
I don ‘t see a clean way to create a scheduled task to run immediately, but you just create one in the distant future, and then send another schtask command to run it:
schtask /run /tn testtask
SCHTASKS /Create [/S system [/U username [/P password]]]
[/RU username [/RP password]] /SC schedule [/MO modifier] [/D day]
[/I idletime] /TN taskname /TR taskrun [/ST starttime] [/M months]
[/SD startdate] [/ED enddate]
Description:
Enables an administrator to create scheduled tasks on a local or
remote systems.
Parameter List:
/S system Specifies the remote system to
connect to. If omitted the system
parameter defaults to the local
system.
/U username Specifies the user context under
which the command should execute.
/P password Specifies the password for the given
user context.
/RU username Specifies the user account (user
context) under which the task runs.
For the system account, valid values
are “”, “NT AUTHORITY\SYSTEM” or
“SYSTEM”.
/RP password Specifies the password for the user.
To prompt for the password, the value
must be either “*” or none.
Password will not effect for the
system account.
/SC schedule Specifies the schedule frequency.
Valid schedule types: MINUTE, HOURLY,
DAILY, WEEKLY, MONTHLY, ONCE,
ONSTART, ONLOGON, ONIDLE.
/MO modifier Refines the schedule type to allow
finer control over schedule
recurrence. Valid values are listed
in the “Modifiers” section below.
/D days Specifies the day of the week to run
the task. Valid values: MON, TUE,
WED, THU, FRI, SAT, SUN and for
MONTHLY schedules 1 – 31 (days of the
month).
/M months Specifies month(s) of the year.
Defaults to the first day of the
month. Valid values: JAN, FEB, MAR,
APR, MAY, JUN, JUL, AUG, SEP, OCT,
NOV, DEC.
/I idletime Specifies the amount of idle time to
wait before running a scheduled
ONIDLE task.
Valid range: 1 – 999 minutes.
/TN taskname Specifies a name which uniquely
identifies this scheduled task.
/TR taskrun Specifies the path and file name of
the program to be run by this
scheduled task.
Example: C:\windows\system32\calc.exe
/ST starttime Specifies the time to run the task.
The time format is HH:MM:SS (24 hour
time) for example, 14:30:00 for
2:30 PM.
/SD startdate Specifies the first date on which the
task runs. The format is
“mm/dd/yyyy”. /ED enddate Specifies the last date when the task
should run. The format is
“mm/dd/yyyy”. /? Displays this help/usage.
Modifiers: Valid values for the /MO switch per schedule type:
MINUTE: 1 – 1439 minutes.
HOURLY: 1 – 23 hours.
DAILY: 1 – 365 days.
WEEKLY: weeks 1 – 52.
ONCE: No modifiers.
ONSTART: No modifiers.
ONLOGON: No modifiers.
ONIDLE: No modifiers.
MONTHLY: 1 – 12, or
FIRST, SECOND, THIRD, FOURTH, LAST, LASTDAY.
Examples:
SCHTASKS /Create /S system /U user /P password /RU runasuser
/RP runaspassword /SC HOURLY /TN rtest1 /TR notepad
SCHTASKS /Create /S system /U domain\user /P password /SC MINUTE
/MO 5 /TN rtest2 /TR calc.exe /ST 12:00:00
/SD 10/20/2001 /ED 10/20/2001 /RU runasuser /RP SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN game
/TR c:\windows\system32\freecell
SCHTASKS /Create /S system /U user /P password /RU runasuser
/RP runaspassword /SC WEEKLY /TN test1 /TR notepad.exe
SCHTASKS /Create /S system /U domain\user /P password /SC MINUTE
/MO 5 /TN test2 /TR c:\windows\system32\notepad.exe
/ST 18:30:00 /RU runasuser /RP *
SCHTASKS /Create /SC MONTHLY /MO first /D SUN /TN cell
/TR c:\windows\system32\freecell /RU runasuser
dir | where {$_.LastWriteTime -ge [DateTime]::Now.AddDays(-1)}
“One Two Three”.split(” “)
One
Two
Three
$Result = “One Two Three”.split(” “)
$Result[1]
Two
“abcde” -match ‘(…)’ ; $matches
True
Name Value
—- —–
1 abc
0 abc
“abcde” -match ‘(^.*d)’ ; $matches
True
Name Value
—- —–
1 abcd
0 abcd
To continue on with the error report code which I started in the last post, I have now figured out how to break up my errpt.txt (get the text file) file into an array where each error is one element:
# This must current be run after # $errorArray is initialized # in the parent shell like this: # # PS> $errorArray = @(); # PS> type errpt.txt | . ./readerrpt.ps1 # PS> $errorArray[43] $Line = "" foreach ($element in $input) { if($element -Match "-----------*") { $errorArray += , $Line $errorArray.Count $Line = "" } else { $Line += "$element`n" } }