Solved

Powershell or vb script that finds the value in the Redirect To: field in IIS 6?

Posted on 2010-09-23
9
1,384 Views
Last Modified: 2012-05-10
Here's the problem, we're migrating from one web server to another.  We have a site that has numerous folders that are configured to redirect to a URL.  I'm going to guess that the radio button labeled "A redirection to a URL" and the form field labeled "Redirect To" are properties that can be searched using a script.

I need to search for and find each one of these folders that does a redirect.

If a Powershell script can help me find these redirects, would someone help me out with the script?  

Tmassa99 was kind enough to help me out with a vb script that starts at the root level, and it worked great starting at the root level.

Now I'm asking for a script that will loop through each folder, and find the redirects for just one site, rather than starting at the root level.

The structure looks like this www.domain.org\folder1\folder1a1\folder1a2 and then www.domain.org\folder2\folder2a\folder2a1.  The challenge is some of these folders have a redirect that may be 2 or 3 folders deep.  And these are what we need to find.

Something like get-childitem c:data -recurse | get-acl | export-csv c:\filename.csv
But instead of getting the acl, get the value for the radio button or the value in the Redirect To field.
0
Comment
Question by:mobot
  • 5
  • 3
9 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 33749478
can u post Tmassa99 script to get an idea of your requirement?
0
 

Author Comment

by:mobot
ID: 33750712
Sure, here it is.  I've tried replacing the word "root" with the name of the folder that I want to search through.  But no joy.  

On Error Resume Next
strComputer = "."
Set objWMIService = GetObject _
    ("winmgmts:{authenticationLevel=pktPrivacy}\\" _
        & strComputer & "\root\microsoftiisv2")

Set colItems = objWMIService.ExecQuery _
    ("SELECT * FROM IIsWebVirtualDirSetting WHERE HttpRedirect != ''")
 
For Each objItem in colItems
    Wscript.Echo "Http Redirect: " & objItem.HttpRedirect
    Wscript.Echo "Name: " & objItem.Name
Next
0
 
LVL 70

Accepted Solution

by:
Chris Dent earned 500 total points
ID: 33751895

!= is not not equal in WQL, you need <>. e.g.

"SELECT * FROM IIsWebVirtualDirSetting WHERE HttpRedirect<>''"

In PS this snippet can be run with:

Get-WmiObject IIsWebVirtualDirSetting -Namespace root\MicrosoftIIsV2 -Filter "HttpRedirect<>''" `
    -Authentication PacketPrivacy -Computer TheWebServer |
  Select-Object Name, HttpRedirect

Note: The Authentication parameter is only supported in PowerShell 2 (not PowerShell 1). PacketPrivacy is required when creating remote connections to WMI for IIS.

Chris
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 33751916

I take it back, WQL will parse != properly, sorry about that. The snippet you have there should return all instances of the redirect, no matter how deeply nested.

Chris
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:mobot
ID: 33755791
Guys my apologies for not being clear about my requirements.  I appreciate your trying to help us.  Let me try again.

I have a folder\dir for a site. www.domain.org.  I start IIS Manager and expand the www.domain.org folder\dir which brings up a list of folders\subdirs.  One is named Archive "\www.domain.org\archive.  I click on the properties for Archive and I see that the radio button for "A Redirection To A URL" is enabled.  The "Redirect To: field has http://www.domain.org/domain/archives" in it.

The Archives folder has two folders within it, Restored and _Notes.  Both of these folders have the "A Redirection To A URL" enabled and "The Redirect To:" field has http://www.domain.org/domain/archives in it.

I need to find all of the folders that have the  "A Redirection To A URL" enabled and "The Redirect To:" field's value.  So we know where it's being redirected to.  For this one site.

I'm trying to avoid having to go through the properties of each folder and it's subfolders to find out which of them is being redirected and where they are being redirected to.

Thanks again.
0
 
LVL 70

Expert Comment

by:Chris Dent
ID: 33755980

IIsWebVirtualDirSetting returns information from all virtual directories, regardless of how deep they are within the structure.

I'll test it again, but the code you have should be able to return details of redirection from anywhere (without you having to write your own recursive subroutine).

Chris
0
 

Author Comment

by:mobot
ID: 33757505
Chris - these aren't virtual directories, they're just folders that have been redirected.  And we're trying to find out which ones they are.  The script does return the details of the redirection for the virtual dirs.
0
 

Author Comment

by:mobot
ID: 33758067
We may also have files that have also been redirected as well. We will need to find out if any folder whether it be a virtual directory or non-virtual directory and if any files have been redirected as well.
0
 

Author Closing Comment

by:mobot
ID: 33782045
Chris thanks - we got it to work the way we need it to using IIsWebDirectorySetting rather than IIsWebVirtualDirSetting in the script.  

And thanks for the tip on the Authentication parameter.
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
A procedure for exporting installed hotfix details of remote computers using powershell
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

21 Experts available now in Live!

Get 1:1 Help Now