Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

JEA Calling Scheduled Task in a Script now fails

$
0
0

Hi,

It looks like one of the security patches has knocked out JEA from running an allowed script unconstrained by a constrained user.

I'm getting back the following error:


An error has occurred while loading script module MSFT_ScheduledTask_v1.0 because it has a different language mode 
than the module manifest. The manifest language mode is ConstrainedLanguage and the module language mode is 
FullLanguage. Ensure all module files are signed or otherwise part of your application allow list configuration.+ CategoryInfo          : InvalidOperation: (:) [Import-Module], PSInvalidOperationException+ FullyQualifiedErrorId : Modules_MismatchedLanguageModes,Microsoft.PowerShell.Commands.ImportModuleCommand 

This was working until I believe Microsoft security updates were applied to the systems.  Using a Jump Server for support personnel to log onto and trigger scripts to run remotely to pull in log files.  Have to use a Scheduled Task to transfer files across the network as the computer account as cannot use a gMSA as the domain is still at 2008 level.

Calling command:

$session = New-PSSession -ComputerName $($ComboBox01.SelectedItem.ToString()) @options
Invoke-Command -Session $session -ScriptBlock {C:\Scripts\FileCopy.ps1 $using:files}
Remove-PSSession $session 

Script File:

# Copy selected files to remote server

[CmdletBinding()]
Param(
    [Parameter(Mandatory=$True,Position=1)]
    [string[]]$FileS
    )

Function Get-Mytime
{
$TimeStamp = Get-Date -Format 'yyyyMMddHHmmss'
"$TimeStamp"
}

#Main Script
#Running with JEA have to actually import ScheduledTasks module to have it function
Import-Module ScheduledTasks
$comp = $env:COMPUTERNAME
Write-Host "Computer Name: " $comp

#TempFile Location
$TempLoc= "c:\Temp"
if(!(Test-Path $TempLoc)){
    md $TempLoc
    Write-Host $TempLoc "Has been created"
    }
else
    {
    Write-Host $TempLoc " Directory Exists"
    }
If([string]::IsNullOrWhiteSpace($Files))
    {
    Write-Host "No Files Found"
    } 
Else
    {
    $TimeStamp = (Get-Mytime)

    #Zip file Name
    $ZipName = $comp+"_"+$TimeStamp+".zip"
    C:\Scripts\7za.exe a $TempLoc\$ZipName  -spf -ssw @($FileS)
    # Run another PS Script to copy to appropriate Enviornment
    # Put zip File information into file to pull for Copy PowerShell Script C:\Temp\PSCopyInfo.txt
    # 
    Out-File -FilePath $ConfigFile -Append string -InputObject $TempLoc
    Out-File -FilePath $ConfigFile -Append string -InputObject $ZipName
    #Create Scheduled task & Run it
    #Create Scheduled Task to run as system and copy zip file to share
    $STName = "$ZipName Copy"
    $STUser= "NT AUTHORITY\SYSTEM"
    $STAction = ScheduledTasks\New-ScheduledTaskAction -Execute powershell.exe -Argument "-File c:\scripts\FileTransfer.ps1"
    $STPastTime = New-TimeSpan -Days 10
    $STResTime = (Get-Date) - $STPastTime
    $STTrigger = ScheduledTasks\New-ScheduledTaskTrigger -Once -At $STResTime 
    $STInfo = ScheduledTasks\Register-ScheduledTask -Action $STAction -Trigger $STTrigger -TaskName $STName -Description "File Copy of $STName" -User $STUser
    Write-Host $STInfo
    ScheduledTasks\Start-ScheduledTask -InputObject $STInfo

    While ((Get-ScheduledTask -TaskName $STInfo.TaskName).State  -ne 'Ready')
    {
    Write-Verbose -Message "Waiting on scheduled task..."
    }
    $TSResult = Get-ScheduledTaskInfo -TaskName $STName
    Write-Host "Scheduled Task results"
    Write-Host "Task Result:" $TSResult|Format-List
    #Remove Scheduled Task
    ScheduledTasks\Unregister-ScheduledTask -InputObject $STInfo -Confirm:$false
    del $TempLoc\$ZipName
    del $ConfigFile
    Write-Host "File Transfer Completed"

Any Ideas?


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

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