Solved

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

Posted on 2010-09-23
9
1,481 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
[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
  • 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 71

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 71

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
 

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 71

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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