Solved

Powershell IIS configuring single site

Posted on 2014-02-02
4
2,137 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
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 70

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

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now