?
Solved

Powershell IIS configuring single site

Posted on 2014-02-02
4
Medium Priority
?
2,400 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 2000 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

801 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