Solved

Powershell IIS configuring single site

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Set OWA language and time zone in Exchange for individuals, all users or per database.
This article will help you understand what HashTables are and how to use them in PowerShell.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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