I have adapted the following script to work on my machines, it works like a dream when run locally but when deployed via azure ad/intune it doesn't work. I can see that it deloys the file but fails when it gets to registering the schedule task. Does anyone have any ideas?
# Author: Oliver Kieselbach # Date: 01/31/2018 # Description: install ps script and register scheduled task # The script is provided "AS IS" with no warranties. # define your PS script here $content = @" Out-File -FilePath "C:\Windows\Temp\test.txt" -Encoding unicode -Force -InputObject "Hello World!""@ # create custom folder and write PS script $path = $(Join-Path $env:ProgramData CustomScripts) if (!(Test-Path $path)) { New-Item -Path $path -ItemType Directory -Force -Confirm:$false } Out-File -FilePath $(Join-Path $env:ProgramData CustomScripts\myScript.ps1) -Encoding unicode -Force -InputObject $content -Confirm:$false # register script as scheduled task $Time = New-ScheduledTaskTrigger -At 12:00 -Daily $User = "SYSTEM" $Action = New-ScheduledTaskAction -Execute "powershell.exe" -Argument "-ex bypass -file `"C:\ProgramData\CustomScripts\myScript.ps1`"" Register-ScheduledTask -TaskName "RunCustomScriptDaily" -Trigger $Time -User $User -Action $Action -Force
↧
azure AD intune powershell script failure
↧