Benutzer mit den meisten Antworten
Schtaks erstellen \ aktuelle Zeit + 2 Min.

Frage
-
Hallo Zusammen
Ich habe einen kleinen einfach Script erstellt der ein *.exe File kopiert und ein schtaks erstellt für die Installation.
Besteht die möglichkeit mit Powershell den parameter Install Zeit /st ( $StartTime ) Automatisch so zu setzen das die aktuelle Zeit genommen wird plus 2 Min?
Hier noch der Script:
$LogDatei = "C:\Logs\Client_Log.txt" $Source = Get-Content C:\System\Systeme.txt $RunAsUser = "NT AUTHORITY\SYSTEM" $TaskName = "Fix" $TaskRun = 'C:\data\Fix\64_3_6_27064.exe /S /v/qn /V' $Schedule = "ONCE" $StartTime = "17:00:00" foreach ($computer in $Source) { $Ping = Test-Connection $computer -count 1 -ErrorAction silentlycontinue If ($Ping -eq $Null) { Write-Host -ForegroundColor Red "Ziel Computer: $computer ist nicht erreichbar!" "Ziel Computer: $computer OFFline" | Out-File $LogDatei -Append } Else { Write-Host -ForegroundColor Green "Ziel Computer: $computer ist erreichbar!" #Copy 64_3_6_27064.exe Write-Host -ForegroundColor White "Start Copy 64_3_6_27064.exe. Ziel \\$computer\c$\data" Copy-Item C:\Users\xxxxxxx\64_3_6_27064.exe -Destination \\$computer\c`$\data #Überprüft ob File Kopiert worden ist Write-Host -ForegroundColor White "Überprüfe ob File Kopiert worden ist" sleep -Seconds 2 if ((Test-Path "\\$computer\c`$\data\64_3_6_27064.exe" -PathType Container) -eq $false) { Write-Host -ForegroundColor Green "File 64_3_6_27064.exe konnte Kopiert werden. Computer:$computer" #schtasks Write-Host -ForegroundColor White "Create schtasks $computer" Start-Sleep -Seconds 5 schtasks /create /S \\$computer /sc $Schedule /tn $TaskName /st $StartTime /ru $RunAsUser /tr $TaskRun } else { Write-Host -ForegroundColor Red "File 64_3_6_27064.exe konnte nicht Kopiert werden. Computer: $computer" "Kopie 64_3_6_27064.exe NOK" | Out-File $LogDatei -Append } } }
Vielen dank
Grüsse
Antworten
-
Du solltest dir angewöhnen das Cmdlet Get-Member möglichst oft einzusetzen!
Get-Member zeigt dir was du mit einem Objekt machen kannst:
Get-Date | Get-Member
TypeName: System.DateTime
Name MemberType Definition
---- ---------- ----------
Add Method System.DateTime Add(System.TimeSpan value)
AddDays Method System.DateTime AddDays(double value)
AddHours Method System.DateTime AddHours(double value)
AddMilliseconds Method System.DateTime AddMilliseconds(double value)
AddMinutes Method System.DateTime AddMinutes(double value)
AddMonths Method System.DateTime AddMonths(int months)
AddSeconds Method System.DateTime AddSeconds(double value)
AddTicks Method System.DateTime AddTicks(long value)
AddYears Method System.DateTime AddYears(int value)
CompareTo Method int CompareTo(System.Object value), int CompareTo(System.DateTime value)
Equals Method bool Equals(System.Object value), bool Equals(System.DateTime value)
GetDateTimeFormats Method string[] GetDateTimeFormats(), string[] GetDateTimeFormats(System.IFormatProvider provider), string[] GetDateTimeFormats(char for...
GetHashCode Method int GetHashCode()
GetType Method type GetType()
GetTypeCode Method System.TypeCode GetTypeCode()
IsDaylightSavingTime Method bool IsDaylightSavingTime()
Subtract Method System.TimeSpan Subtract(System.DateTime value), System.DateTime Subtract(System.TimeSpan value)
ToBinary Method long ToBinary()
ToFileTime Method long ToFileTime()
ToFileTimeUtc Method long ToFileTimeUtc()
ToLocalTime Method System.DateTime ToLocalTime()
ToLongDateString Method string ToLongDateString()
ToLongTimeString Method string ToLongTimeString()
ToOADate Method double ToOADate()
ToShortDateString Method string ToShortDateString()
ToShortTimeString Method string ToShortTimeString()
ToString Method string ToString(), string ToString(string format), string ToString(System.IFormatProvider provider), string ToString(string forma...
ToUniversalTime Method System.DateTime ToUniversalTime()
DisplayHint NoteProperty Microsoft.PowerShell.Commands.DisplayHintType DisplayHint=DateTime
Date Property System.DateTime Date {get;}
Day Property System.Int32 Day {get;}
DayOfWeek Property System.DayOfWeek DayOfWeek {get;}
DayOfYear Property System.Int32 DayOfYear {get;}
Hour Property System.Int32 Hour {get;}
Kind Property System.DateTimeKind Kind {get;}
Millisecond Property System.Int32 Millisecond {get;}
Minute Property System.Int32 Minute {get;}
Month Property System.Int32 Month {get;}
Second Property System.Int32 Second {get;}
Ticks Property System.Int64 Ticks {get;}
TimeOfDay Property System.TimeSpan TimeOfDay {get;}
Year Property System.Int32 Year {get;}
DateTime ScriptProperty System.Object DateTime {get=if ((& { Set-StrictMode -Version 1; $this.DisplayHint }) -ieq "Date")...Dann siehst du das du die Methode AddMinutes() benutzen kannst!
/st ((Get-Date).AddMinutes(2).Tostring("hh:mm:ss"))
Please click “Mark as Answer” if my post answers your question and click “Vote As Helpful” if my Post helps you.
Bitte markiere hilfreiche Beiträge von mir als “Als Hilfreich bewerten” und Beiträge die deine Frage ganz oder teilweise beantwortet haben als “Als Antwort markieren”.
My PowerShell Blog http://www.admin-source.info
[string](0..21|%{[char][int]([int]("{0:d}" -f 0x28)+('755964655967-86965747271757624-8796158066061').substring(($_*2),2))})-replace' '
German ? Come to German PowerShell Forum!
- Als Antwort markiert Disco_G Donnerstag, 12. September 2013 10:39
- Bearbeitet Peter Kriegel Freitag, 13. September 2013 07:35 ugly typo