Advertisement
zalupaster322

Check/Install IIS powershell

Apr 27th, 2021
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script is used to install the web server IIS if it is not installed on server
  2.  
  3. #region start timer
  4. $startTime = Get-Date
  5. Write-Output "SCRIPT START - $startTime"
  6. #endregion
  7.  
  8. try {
  9.     if ((Get-WindowsFeature Web-Server).InstallState -eq "Installed") {
  10.         Write-Host "IIS is installed on server"
  11.     }
  12.     else {
  13.         Write-Host "IIS is not installed on server"
  14.  
  15.         #region IIS instalation
  16.         $iisStartTime = Get-Date
  17.         Write-Host "$iisStartTime - IIS installation started"
  18.  
  19.         Install-WindowsFeature -name Web-Server -IncludeManagementTools -IncludeAllSubFeature
  20.  
  21.         $iisFinsihedTime = Get-Date
  22.         Write-Host "$iisFinsihedTime - IIS installation finished"
  23.         #endregion IIS instalation
  24.     }
  25. }
  26. catch {
  27.     $errorMessage = $_.Exception.Message
  28.     Write-Error "Uexpected error with IIS cehck/instalation. $errorMessage"
  29.     throw $_
  30. }
  31.  
  32.  
  33. #region start timer
  34. $endTime = Get-Date
  35. Write-Output "SCRIPT FINISHED - $endTime"
  36. #endregion
  37.  
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement