Just wondering if anyone would be able to advise what I can use to hide the box for the following code during the scheduled task please.
I have tried the -Windowsstyle hidden command but it still fails where I put it.
Thanks in advance
Joe
$Folder = 'C:Scripts'
$File = 'C:ScriptsSelfScan.exe'
$ServerUrl = 'sdpondemand.manageengine.com'
if (Test-Path -Path $Folder) {
Write-Host "Path exists!"
} else {
New-Item -Path $Folder -ItemType Directory
}
if (Test-Path -Path $File -PathType Leaf) {
Write-Host "File Exists"
} else {
$url = "https://" + $ServerUrl + "/scanscript/SelfScan.exe"
wget $url -outfile $File
}
Write-Host "Script Downloaded."
# Uncomment the below lines based on where you wish to send the data.
# If it is the probe, then uncomment the ip address line and comment the apikey one. or vice versa
#$selfScan = "192.16.100.100"
$selfScan = "apiKey=1003.f919381bd393317bf8816ce4e07a142d.c2c4a69b0e764fc9d372b14e49a29c1d server=torus." + $ServerUrl
Write-Host $selfScan
#DO NOT EDIT BELOW THIS LINE
$TaskUser = New-ScheduledTaskPrincipal -GroupId "BUILTINUsers" -RunLevel Highest
$action=New-ScheduledTaskAction -Execute $File -Argument $selfScan
$taskName = "ASSETSELFSCAN2.0_TASK"
$taskExists = Get-ScheduledTask | Where-Object {$_.TaskName -like $taskName }
if($taskExists) {
Write-Host "Task Exists"
} else {
$trigger=New-ScheduledTaskTrigger -DAILY -AT 15:40
Register-ScheduledTask -Action $action -Trigger $trigger -TaskName $taskName -Principal $TaskUser
}
I tried the -windowsstyle hidden command but this still executed in the users view
New contributor