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

Powershell IIS issue

I have a powershell script that should return the status of my website running locally on my Windows 7 PC and IIS 7.

Why is it that the "State" of my website does not output?
How do I prevent the actual script/code from beign output?

Here is the script:
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
     
      $iis = New-Object Microsoft.Web.Administration.ServerManager
     
      [string] $host2 = [System.Net.Dns]::GetHostName()

           Write-Host "Server name: $host2"


             $site_name = $iis.sites["mtest.com"]


          Write-Host "$site_name"


            $site_state = $iis.sites["mtest.com"].state
           
         Write-Host "$site_state"


Here is the output

PS C:\Users\Milligram>       [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
     
      $iis = New-Object Microsoft.Web.Administration.ServerManager
     
      [string] $host2 = [System.Net.Dns]::GetHostName()

           Write-Host "Server name: $host2"


             $site_name = $iis.sites["mtest.com"]


          Write-Host "$site_name"


            $site_state = $iis.sites["mtest.com"].state
           
         Write-Host "$site_state"

GAC    Version        Location                                                                                                                                                                                                                                  
---    -------        --------                                                                                                                                                                                                                                  
True   v2.0.50727     C:\Windows\assembly\GAC_MSIL\Microsoft.Web.Administration\7.0.0.0__31bf3856ad364e35\Microsoft.Web.Administration.dll                                                                                                                      
Server name: Milligram-PC
mtest.com



0
wademi
Asked:
wademi
  • 8
  • 4
1 Solution
 
jessc7Commented:
Try entering one line at a time, or make it a *.ps1 file to execute.
0
 
wademiAuthor Commented:
jessc7: What do you mean by Try entering one line at a time?
I am using the powershell ISE . What diffrence would make if i make it a ps1?
0
 
jessc7Commented:
wademi, I apologize, ignore my previous post. I misread the output. I'm testing a dev VM right now...

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
jessc7Commented:
Try this:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$iis = New-Object Microsoft.Web.Administration.ServerManager 
[string] $host2 = [System.Net.Dns]::GetHostName()
Write-Host "Server name: $host2"
$site_name = $iis.sites["mtest.com"]
Write-Host "$site_name"
# OLD
# $site_state = $iis.sites["mtest.com"].state
# NEW
$site_state = $site_name.state
Write-Host "$site_state"

Open in new window

0
 
jessc7Commented:
Also, once you have gotten this far in the script:

$site_name = $iis.sites["mtest.com"]

Just type $site_name and hit Enter. PowerShell will return a list of accessible properties and their values. Just FYI.
0
 
wademiAuthor Commented:
Thanks for your help jessc7:
The new script that you posted yields the same results as before. I don not get the state of the site in the output.

Also after typing $site_name and hit enter it just goes to a new line.
0
 
jessc7Commented:
Hmm... that worked on my machine. I'll look again.
0
 
jessc7Commented:
Is mtest.com the name of the site when you look under "Sites" in the IIS manager?
0
 
wademiAuthor Commented:
Yes it is. See the attached
10-9-2011-3-17-26-PM.png
0
 
jessc7Commented:
If you run this, do you see a list of sites matching the above?

$iis.sites | select Name
0
 
jessc7Commented:
That assumes you've already loaded the IIS snapins, etc.
0
 
wademiAuthor Commented:
I tries a differnt server and it works. I may need to look at this server. Thanks.
0

Featured Post

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

  • 8
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now