Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2314

Schtaks erstellen \ aktuelle Zeit + 2 Min.

$
0
0

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


Viewing all articles
Browse latest Browse all 2314


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>