Remotely configure System.Diagnostics.Eventing.Reader.EventLogConfiguration

Hi

Sorry if this is a stupid question, but I’ve not worked much or anything at all with New-Object and things related to it.

I’m looking for a way to do what is posted here:

But if possible I would like to run it against several servers remotely, instead of running it locally as the post describes.

This would be the code:

$logName = ‘Microsoft-Windows-PrintService/Operational’

$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled=$true
$log.SaveChanges()

Most of these server still have PS V2 installed (2008 R2), and some have V4 (2012 R2)

Any assistance or help pointing me towards how I can solve this or where and what I could read to understand how to solve this would be very appreciated.

Do you have .NET 3.5 or later installed on your Win2008 R2 machines?

If yes, the following code with the additional Add-Type command should work:

Add-Type -AssemblyName System.Core $logName = 'Microsoft-Windows-PrintService/Operational' $log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName $log.IsEnabled=$true $log.SaveChanges()

Thanks for your reply Daniel.
What does that Add-Type row actually do?
The “code” in my first post works if I run it locally, I just wanted to be able to run it against multiple machines at the same time.

I realized how stupid I was though, all I needed to do was to put the “code” inside invoke-command, like this:

Invoke-Command -ComputerName XYZ {
$logName = ‘Microsoft-Windows-PrintService/Operational’
$log = New-Object System.Diagnostics.Eventing.Reader.EventLogConfiguration $logName
$log.IsEnabled=$true
$log.SaveChanges()
}

If I’m not mistaken I could just enter some more computer names in that command and problem would be solved.
Easy enough IF PS-remoting is enabled on all servers.
Is it possible to do this without invoke-command or more specifically without PS-remoting enabled?

“Add-Type -AssemblyName” loads .NET assemblies into a PowerShell session. If you are running PowerShell 2.0 with .NET Framework 3.5 installed you’ll need to run “Add-Type -AssemblyName System.Core” before your other code.

If you have a software deployment system (like SCCM, Altiris, Tivoli/BigFix, etc.) you can deploy the script and run it locally on the machine or use Sysinternals PSExec.

However I would try to get remoting enabled via Group Policy for all your servers.