The problem is the Active Directory schema in domain’s forest needs to be updated to Windows Server 2012.
And use gMSA
Can't register sheduled task with managed service account
Hi everybody!
In Active Directory level 2008 r2 create MSA.
Install MSA on target server.
Create scheduled task
$action = New-ScheduledTaskAction -Execute 'D:\Consultant\cons.exe' -Argument '/adm /base* /receive_inet /sendstt /process=1 /yes' -WorkingDirectory 'C:\ConsUserData'
$trigger = New-ScheduledTaskTrigger -At '02:13' -Daily
$principal = New-ScheduledTaskPrincipal -UserId "ALM\ConsPlusUpdater$" -LogonType Password
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -StartWhenAvailable -RestartCount "3" -RestartInterval (New-TimeSpan -Minutes "15") -ExecutionTimeLimit (New-TimeSpan -Hours "4")
$task = New-ScheduledTask -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Description 'Задача обновления файлов справочно-правовой системы "Консультант+"'
Register-ScheduledTask -TaskName "UpdateLocalConsultantPlus" -InputObject $task
But I get error:
Register-ScheduledTask : Имя файла или его расширение имеет слишком большую длину.
строка:1 знак:1
+ Register-ScheduledTask -TaskName "UpdateLocalConsultantPlus" -TaskPath \ -InputO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTa
sk], CimException
+ FullyQualifiedErrorId : HRESULT 0x800700ce,Register-ScheduledTask
Extendet view:
$Error[0] | fl -Force
writeErrorStream : True
OriginInfo :
Exception : Microsoft.Management.Infrastructure.CimException: Имя файла или его расширение имеет слишком большую длину.
в Microsoft.Management.Infrastructure.Internal.Operations.CimAsyncObserverProxyBase`1.ProcessNativeCallback(OperationCallbackProcessingContext callbackProcessingContext, T currentItem, Boolean moreResults, MiResult operationResult, String errorMessage, InstanceHandle errorDetailsHandle)
TargetObject : PS_ScheduledTask
CategoryInfo : NotSpecified: (PS_ScheduledTask:Root/Microsoft/...S_ScheduledTask) [Register-ScheduledTask], CimException
FullyQualifiedErrorId : HRESULT 0x800700ce,Register-ScheduledTask
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace :
PipelineIterationInfo : {0, 1}
PSMessageDetails :
Windows for business | Windows Server | User experience | PowerShell
-
Леонид Литвинюк 96 Reputation points
2021-11-09T13:54:18.223+00:00
2 additional answers
Sort by: Most helpful
-
Limitless Technology 39,926 Reputation points
2021-10-28T18:51:09.623+00:00 Hello @Леонид Литвинюк ,
The error 0x800700ce = COR_E_PATHTOOLONG as recorded here https://learn.microsoft.com/en-us/dotnet/api/system.io.pathtoolongexception?view=net-5.0
In this case one of the paths used or called in the script contains a path too long. I would recommend to shorten the paths. In case that you are using a network share drive, bear in mind that the total path is not the one of the shared drive, but the local path in the disk.
Hope this helps with your query,
---------
--If the reply is helpful, please Upvote and Accept as answer--
-
Леонид Литвинюк 96 Reputation points
2021-10-29T13:56:02.29+00:00 After edit
$principal = New-ScheduledTaskPrincipal -UserId 'ALM\ConsPlusUpdater$' -LogonType ServiceAccount
task was registered.