I'm using the MonthCalendar in a project to scheduled tasks on a remote server. Unfortunately if you pick a single digit day such as the ninth or month such as February the output is 2/9/2012. Powershell doesn't recognize single digits as valid entries. How do I modify the MonthCalendar so that it outputs as 02/09/2012 and not 2/9/2012?
$m = $monthcalendar1.SelectionEnd.month
$d = $monthcalendar1.SelectionEnd.day
$y = $monthcalendar1.SelectionEnd.Year
Function Create-ScheduledTask {
param(
[string]$ComputerName2 = "myserver",
[string]$RunAsUser2 = "domainaccount",
[string]$RunPass2 = "password",
[string]$TaskName2 = "$taskname",
[string]$TaskRun2 = "'PowerShell.exe -NoLogo -File myserverc$powershelldisable-userDisableUserSchedualed.ps1'",
[string]$Schedule = "$hour"+":"+"$minute",
[string]$Date2 = "$m"+"/"+"$d"+"/"+"$y"
)
$Command2 = "schtasks.exe /create /s $ComputerName2 /U $RunAsUser2 /P $RunPass2 /ru $RunAsUser2 /rp $RunPass2 /tn $TaskName2 /tr $TaskRun2 /sc ONCE /sd $date2 /st $Schedule /F"
Invoke-Expression $Command2
modifying output from MonthCalendar
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
modifying output from MonthCalendar
The DateTime object has a ToString function that allows you to format the date:
http://msdn.microsoft.com/en-us/library ... tring.aspx
In your case, you will need to do the following:
$date.ToString('MM/dd/yyyy')
David
http://msdn.microsoft.com/en-us/library ... tring.aspx
In your case, you will need to do the following:
$date.ToString('MM/dd/yyyy')
David
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.