0

I've got a simple Get-ScheduledTask command that gives me a simple output:

    Get-ScheduledTask | select -last 1
    
    TaskPath                                       TaskName                          State
    --------                                       --------                          -----
    \Microsoft\Windows\WS\                         WSTask                            Ready

When I call this same command through Invoke-Command (run from and on the same computer as above), I sometimes get a very similar output:

    Invoke-Command -ComputerName PRD-APIEXT001 -ScriptBlock {Get-ScheduledTask |select -last 1 } -Credential $cred
    
    TaskPath                                       TaskName                          State      PSComputerName
    --------                                       --------                          -----      --------------
    \Microsoft\Windows\WS\                         WSTask                            Ready      PRD-APIEXT001

But sometimes, I get a much more verbose output:

    Invoke-Command -ComputerName PRD-APIEXT001 -ScriptBlock {Get-ScheduledTask |select -last 1} -Credential $cred
    
    
    PSComputerName     : PRD-APIEXT001
    RunspaceId         : [REDACTED]
    Actions            : {MSFT_TaskComHandlerAction}
    Author             : Microsoft Corporation
    Date               : 2010-10-27T17:18:44.0816608
    Description        : Windows Store Maintenance Task
    Documentation      :
    Principal          : MSFT_TaskPrincipal2
    SecurityDescriptor : [REDACTED]
    Settings           : MSFT_TaskSettings3
    Source             : wsservice.dll
    State              : 3
    TaskName           : WSTask
    TaskPath           : \Microsoft\Windows\WS\
    Triggers           :
    URI                : \Microsoft\Windows\WS\WSTask
    Version            :

I can figure out no rhyme or reason why it's sometimes the simple output, and sometimes the verbose output, except that it only seems to change in one direction; from verbose to simple. That is, once a PowerShell session shows the simple output, it never seems to go back to the verbose output. But sometimes a session that used to be showing verbose output will switch to the simple.

Now, I know from this StackOverflow question that Invoke-Command adds properties to each object that it returns.

But I am still at a loss as to why it would sometimes give the the table-based output and sometimes give me a list of properties as the output.

Can anybody tell me what might be happening here?

I am using PowerShell version 5.1.14409.1018.

2
  • The remote computer is always the same? Commented Jul 31, 2020 at 17:44
  • Yes, and it's the same computer I'm running the command from. Commented Jul 31, 2020 at 18:49

1 Answer 1

1

It looks like until the ScheduledTasks module is loaded, either with import-module or running get-scheduledtask locally, the display info for that type of object isn't loaded.

Import-Module ScheduledTasks
icm localhost { get-scheduledtask | select -last 1 }  # elevated prompt for localhost

TaskPath                                       TaskName
--------                                       --------
\Microsoft\XblGameSave\                        XblGameSaveTaskLogon


Get-ScheduledTask | select -last 1 | get-member | findstr TypeName

TypeName: 
'Microsoft.Management.Infrastructure.CimInstance#Root/Microsoft/Windows/TaskScheduler/MSFT_ScheduledTask'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.