Remoting and Assembly

This topic contains 8 replies, has 3 voices, and was last updated by Profile photo of Ton Siemons Ton Siemons 2 years, 6 months ago.

  • Author
    Posts
  • #15618
    Profile photo of Ton Siemons
    Ton Siemons
    Participant

    I try to empty the task scheduler log remote on 2008 R2 servers with

    [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("Microsoft-Windows-TaskScheduler/Operational")
    

    Can't load the assembly. Error:
    Unable to find type [System.Diagnostics.Eventing.Reader.EventLogSession]: make sure that the assembly containing this t
    ype is loaded.

    preload like

    [System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics.Eventing.Reader.EventLogSession")

    does not work.
    Fired locally it works, just not in a remote session. Any idea?

  • #15619
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Do you have the .NET Framework 3.5 or later installed on the remote server?

    The EventLogSession class was introduced with that version and you shouldn't need to load anything because the class is part of System.Core which is being loaded automatically.

  • #15620
    Profile photo of Ton Siemons
    Ton Siemons
    Participant

    Yes sir. Like I said: local powershell the snippet works, but not when using remoting.

  • #15624
    Profile photo of Ton Siemons
    Ton Siemons
    Participant

    Yes, it works fine on our 2012/2012 R2 servers, but not on 2008 R2.
    Unfortunately the majority of the servers are still 2008R2

  • #15625
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    It works for me remotely on Win2008 R2 servers as well. That why I've asked if the .NET Framework 3.5 or later is installed.

    Please be so kind to run below command against one of your Win2008 R2 servers and post the output.

    Invoke-Command -ComputerName RDS01 -ScriptBlock { [appdomain]::currentdomain.getassemblies() | Where-Object FullName -like '*System.Core*' } | Format-Table -Property ImageRuntimeVersion, FullName -AutoSize

  • #15628
    Profile photo of Ton Siemons
    Ton Siemons
    Participant

    Had to adapt the code a bit to let it work with posh 2
    I'm getting no returns. locally nor remote.

    But it still works on the server it self.

  • #15792
    Profile photo of Ton Siemons
    Ton Siemons
    Participant

    Thank you, i'm back from an extended holliday weekend and I can confirm this works

  • #15623
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    Your code runs without issue for me when I run it from my test Windows 8.1 client machine against my test Windows 2012R2 web server:

    
    Invoke-Command -ComputerName web01 {
        [System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics.Eventing.Reader.EventLogSession")
        [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("Microsoft-Windows-TaskScheduler/Operational")
    }
    

    It also works without adding the assembly:

    
    Invoke-Command -ComputerName web01 {
        [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog("Microsoft-Windows-TaskScheduler/Operational")
    }
    
  • #15629
    Profile photo of Daniel Krebs
    Daniel Krebs
    Participant

    Ok. I think I've figured it out using a fresh Win2008 R2 install in a VM.

    1. You've PowerShell 2.0 and .NET Framework 3.5.1 installed.
    2. [System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics.Eventing.Reader.EventLogSession")
    Does not load the System.Core which contains the class you want to use.

    A solution that works on my fresh machine with PowerShell 2.0 and .NET 3.5 is:
    Invoke-Command -ComputerName RDS02 -ScriptBlock { Add-Type -AssemblyName System.Core; [System.Diagnostics.Eventing.Reader.EventLogSession]::GlobalSession.ClearLog('Microsoft-Windows-TaskScheduler/Operational') }

You must be logged in to reply to this topic.