• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1609
  • Last Modified:

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

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
mobot
Asked:
mobot
  • 5
  • 3
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
can u post Tmassa99 script to get an idea of your requirement?
0
 
mobotAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

!= 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
Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

 
Chris DentPowerShell DeveloperCommented:

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
 
mobotAuthor Commented:
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
 
Chris DentPowerShell DeveloperCommented:

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
 
mobotAuthor Commented:
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
 
mobotAuthor Commented:
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
 
mobotAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Simplify Active Directory Administration

Administration of Active Directory does not have to be hard.  Too often what should be a simple task is made more difficult than it needs to be.The solution?  Hyena from SystemTools Software.  With ease-of-use as well as powerful importing and bulk updating capabilities.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now