I'm trying to avoid using the IIS cmdlet since I believe that would mean I'd need to install it on the server first. I am trying to make this install as automated as possible, so I would like to avoid the need to install new cmdlets if I can. Our servers already
come with Powershell installed, so I'm trying to work off of that.
Tray_Harriso...
11 Posts
Appcmd to change log folder works from command prompt but not powershell
Dec 30, 2010 06:06 PM|LINK
c:\windows\system32\inetsrv\appcmd.exe set config -section:sites -siteDefaults.logfile.directory:e:\IISLogFiles
But if I try to run that exact command from a Powershell window, I get the following error:
PS C:\Users\User> c:\windows\system32\inetsrv\appcmd.exe set config -section:sites -siteDefaults.logfile.directory :e:\IISLogFiles ERROR ( message:Cannot find SITE object with identifier ".logfile.directory:e:\IISLogFiles". )
Any ideas why? My other appcmd commands seem to work just fine when I call them from Powershell.
jae hoon kim
8 Posts
Re: Appcmd to change log folder works from command prompt but not powershell
Dec 30, 2010 11:41 PM|LINK
why don't you use powershell cmdlet?
you can do same job using powershell..
$siteItem = Get-ItemProperty 'IIS:\Sites\site1'
$siteItem.logFile.Directory = "e:\IISLogFiles"
Tray_Harriso...
11 Posts
Re: Appcmd to change log folder works from command prompt but not powershell
Jan 04, 2011 03:36 PM|LINK
kloinerFeigl...
118 Posts
Re: Appcmd to change log folder works from command prompt but not powershell
Jan 04, 2011 06:58 PM|LINK
you could try this using the Webadministration API:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$iis = new-object Microsoft.Web.Administration.ServerManager
$web = $iis.Sites["test"]
#show current logpath
$web.LogFile.Directory
#set new logpath, must be existing
$web.LogFile.Directory = "F:\Logfiles\"
$iis.CommitChanges()
or for sitedefaults:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$iis = new-object Microsoft.Web.Administration.ServerManager
#show current sitedefault logpath
$iis.SiteDefaults.LogFile.Directory
#set new sitedefault logpath, must be existing
$iis.SiteDefaults.LogFile.Directory = "F:\Logfiles\"
$iis.CommitChanges()
kloinerFeigl...
118 Posts
Re: Appcmd to change log folder works from command prompt but not powershell
Jan 04, 2011 07:10 PM|LINK
c:\windows\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /siteDefaults.logFile.directory:"e:\IISLogFiles" /commit:apphost
this will work to more information can be found here:
http://www.iis.net/ConfigReference/system.applicationHost/sites/siteDefaults/logFile
...
Tray_Harriso...
11 Posts
Re: Appcmd to change log folder works from command prompt but not powershell
Jan 04, 2011 07:18 PM|LINK