IIS 7.5 w3c logging fields

by qvantas at 2013-01-07 12:33:43

Hi all!
Is it possible to use powershell to change the w3c logging fields?
I only want a few of these fields to be checked.

Cheers!

//Johan
by JasonHelmick at 2013-01-15 12:20:44
Hey Johan!

Here’s one way to do it using Set-WebConfigurationProperty cmdlet from the WebAdministration module. The -Value parameter takes a single string with the options you want enabled separated by comma’s. This is not a powershell array, so make sure its surrounded in quotes. Below I enabled only Date, Time and the ClientIP for the log.

Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"

To a the current list of enabled items:

Get-WebConfiguration -filter system.applicationhost/sites/sitedefaults/logfile | Select-Object -ExpandProperty logExtFileFlags

Hope this helps!

Jason
by qvantas at 2013-01-17 03:04:22
Hi Jason!
This works great when im logged on to the server.
Is it possible to deploy this on remote servers? Have a text file with alot of webservers.

Cheers,

Johan
by JasonHelmick at 2013-01-17 06:05:50
Sure! But you need to have PowerShell Remoting enabled. So, if you do just use the Invoke-Commmand…
Invoke-Command -ComputerName Web1, Web2 {set-WebConffigurationProperty blah blah blah }

If you don’t, take a look at Don’s ebook on turning it on. "Secrets of PowerShell Remoting" http://powershellbooks.com

Cheers!
by qvantas at 2013-01-17 06:39:52
Hi Jason!
Thanks for ur help :slight_smile:
Have enabled "psremoting" but i still dont get it to work :frowning:
Any ideas?

PS H:> Import-Module webadministration
PS H:> invoke-command -computername servername {Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/
SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"}

The term ‘Set-WebConfigurationProperty’ is not recognized as the name of a cmdlet, function, script file, or operable p
rogram. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (Set-WebConfigurationProperty:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
by JasonHelmick at 2013-01-17 06:43:49
:wink:

Sure! You really close to getting it to work…here’s the issue…

You need to import the module on the remote computer…do this…

Invoke-Command -ComputerName server {Import-Module WebAdministration}

Then

Invoke-Command -ComputerName server {Set-webConfigurationProperty blah blah}

Did this help?

Jason
by qvantas at 2013-01-17 06:54:18
No :frowning: Same error
i can do things like invoke-command -computername {get-process)

Regards
Johan
by ArtB0514 at 2013-01-17 11:23:52
If you want to invoke several commands on a remote computer and remember context and values between the commands then you need to set up a PSSession and run the commands in it.

$MySession = New-PSSession -ComputerName server
Invoke-Command -Session $MySession -ScriptBlock {Import-Module WebAdministration}
Invoke-Command -Session $MySession -ScriptBlock {Set-webConfigurationProperty blah blah}
Remove-PSSession $MySession


Or you need to put all the commands that you want to run into a single scriptblock.

Invoke-Command -ComputerName server -ScriptBlock {
Import-Module WebAdministration
Set-webConfigurationProperty blah blah
}
by JasonHelmick at 2013-01-18 09:08:52
ArtB0514 - Great contribution! thank you!

Johan - Let me ask a really dumb question…is IIS installed on the remote computers? - and if so, what version of IIS are you running?

So, Enter-PsSession -ComputerName RemoteServer

then

Get-Module web

Is there a webadministration module listed?
by qvantas at 2013-01-21 00:03:08
Hi admins!!
Thanks for your reply’s, really appreciate it :slight_smile:
Weekend is over and im back to my computers…

PS C:> Invoke-Command -ComputerName Servername {import-module webadministration | Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"}
The term ‘Set-WebConfigurationProperty’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a pa
th was included, verify that the path is correct and try again.
+ CategoryInfo : ObjectNotFound: (Set-WebConfigurationProperty:String) , CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName : Servername


But this works:
PS C:> $MySession = New-PSSession -ComputerName Servername
Invoke-Command -Session $MySession -ScriptBlock {Import-Module WebAdministration}
Invoke-Command -Session $MySession -ScriptBlock {Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"}
Remove-PSSession $MySession

But this is only a connection to one server, i now have to figure out how this can be run on multiple servers.

Cheers,

Johan
by qvantas at 2013-01-21 01:28:58
hi!

i think ive nailed it :slight_smile:

$server = get-content C:\skydrive\scripts\test.txt
$MySession = New-PSSession -ComputerName $server
ForEach ($srv in $server)
{Invoke-Command -Session $MySession -ScriptBlock {Import-Module WebAdministration}
Invoke-Command -Session $MySession -ScriptBlock {Set-WebConfigurationProperty -Filter System.Applicationhost/Sites/SiteDefaults/logfile -Name LogExtFileFlags -Value "Date,Time,ClientIP"}
}
Remove-PSSession $MySession

Thanks!!
by JasonHelmick at 2013-01-21 07:12:42
Hey Johan!

the -ComputerName of New-PsSession and Invoke-Command accepts multiple values seperated by comma’s…so…as an example

New-PsSession -ComputerName server1, Server2, Server3

Jason