Solved

Powershell IIS configuring single site

Posted on 2014-02-02
4
2,308 Views
Last Modified: 2014-02-05
I am writing/copying a PowerShell script, for use in configuring an IIS 7 site.

I need to use native commands like below:
New-WebVirtualDirectory -Site $webhost -Name usage -PhysicalPath e:\sites\$websitename\usage -force

How can I re-code these snippets of code, to be PowerShell native, and use variables:?
Not using the appcmd.exe
-----
1)

# Enable 'Directory Browsing' on Virtual Directory
C:\Windows\System32\inetsrv\appcmd.exe set config "$webhost/usage" -section:system.webServer/directoryBrowse /enabled:"True" /showFlags:"Date, Time, Size, Extension"

-----

2)

# Sets logging fields under "logging" on the site.
$a = get-itemproperty IIS:\Sites\$webhost
$a.logFile.logExtFileFlags = "Date,Time,ClientIP,UserName,SiteName,ComputerName,ServerIP"
$a.logFile.directory = "E:\sites\$websitename\logs1"
$a | set-item

-----

3)

I am having difficulty finding a way to use a variable ($webhost) in this line:
Set-WebConfigurationProperty -Filter '/system.applicationHost/sites/site[@name="$webhost]/LogFile' -name localTimeRollover -value true

-----

4)

Not able to find code on how to change the log schedule to "Daily"
0
Comment
Question by:raymoyneur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39834879
Import-Module WebAdministration

#1) set directoryBrowse configuration
Set-WebConfigurationProperty -filter /system.webServer/directoryBrowse -name enabled -Value $true -PSPath 'IIS:\Sites\$webhost\usage'

#2) change log directory and flags
Set-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.directory -value "E:\sites\$websitename\logs1"

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

#3) it looks like u forgot the closing quotes, tru this one:
Set-WebConfigurationProperty -Filter '/system.applicationHost/sites/site[@name="$webhost"]/LogFile' -name localTimeRollover -value true

#4) change log file rollover scheduler (just like number 2)
Set-WebConfigurationProperty "/system.applicationHost/sites/siteDefaults" -name logfile.period -value "Daily"

Open in new window

0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 39835129
WebHost is the site under which you are creating your virtual directory.

For example, we might set $webhost to "Default Web Site", then your new Virtual Directory is created under there. i.e.
$Webhost = "Default Web Site"

Open in new window

sedgwick has already converted the appcmd parts so I'm reluctant to repeat that. Are you able to piece everything together from here? If not, just yell I'm sure we can get this into a happy state.

Cheers,

Chris
0
 

Author Closing Comment

by:raymoyneur
ID: 39835776
Thanks very much,

I was able to get the code working as expected.

Very appreciated...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A procedure for exporting installed hotfix details of remote computers using powershell
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question