Solved

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

Posted on 2010-09-23
9
1,363 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
Comment Utility
can u post Tmassa99 script to get an idea of your requirement?
0
 

Author Comment

by:mobot
Comment Utility
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
Comment Utility

!= 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
Comment Utility

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

Author Comment

by:mobot
Comment Utility
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
Comment Utility

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

763 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

11 Experts available now in Live!

Get 1:1 Help Now