Solved

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

Posted on 2010-09-23
9
1,419 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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
 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A phishing scam that claims a recipient’s credit card details have been “suspended” is the latest trend in spoof emails.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

828 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