title: How can I check for stopped websites and starting those websites using powershell functions
body: <p>Im currently updating and replacing old outdated nightly scheduled batch files with new self sufficient PowerShell scripts.</p>
  
  <p>The one I am having trouble with is website starts.  I am able to use the current test code to get the list of sites and display them but cannot figure out a way to correctly start them if they are stopped.</p>
  
  <pre><code>Set-ExecutionPolicy Unrestricted
  start-transcript -path C:\TESTSTART.TXT
  #function to get list of websites that are currently stopped
  function Get-StoppedSites {
      Import-Module WebAdministration
      $website = Get-ChildItem IIS:\Sites | where {$_.State -eq 'Stopped'}
      write-host "$website is stopped"
      }
  #function to start the stopped website
  function StartSites {
      param(
      $websitename
      )
      start-website $websitename
      write-host "$website was started"
      }
  $Script = Get-StoppedSites
  $Script | ForEach-Object{StartSites -websitename $website} 
  stop-transcript
  </code></pre>
  
  <p>When I call this from powershell it acts like it completed with no errors but the website is not started that I had stopped.  Windows 2008 R2 server, PS 2.0.  I will be running this on 2003 servers once it's ready to roll out though.</p>
  
  <p>Here is my transcript:</p>
  
  <pre><code>Transcript started, output file is C:\TESTSTART.TXT
   is stopped
  Start-Website : Cannot validate argument on parameter 'Name'. The argument is null. Supply a non-null argument and try 
  the command again.
  At C:\Users\Administrator\Desktop\test.ps1:14 char:18
  +     start-website &lt;&lt;&lt;&lt;  $websitename
      + CategoryInfo          : InvalidData: (:) [Start-Website], ParameterBindingValidationException
      + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.IIs.PowerShell.Provider.StartWebsiteCommand
  
   was started
  **********************
  Windows PowerShell Transcript End
  End time: 20120823150248
  </code></pre>
  
  <p>Can you guys help me figure out where/what I'm doing wrong here?  Thanks!</p>