Q:

PowerShell Script to restart the Application Pools of WFEs

Need to create a PowerShell script to recycle the Application Pool of my WFE - Dev,Staging & Production servers of my SP 2013 Farm.  
I tried code mentioned
 here  
But somehow as mentioned in the blog, it seems, its applicable to Win Server 2008 only.
Also I tried  this 
too:
  # Load IIS module:
 Import-Module WebAdministration
 # Set a name of the site we want to recycle the pool for:
 $site = "Default Web Site"
 # Get pool name by the site name:
 $pool = (Get-Item "IIS:\Sites\$site"| Select-Object     
 applicationPool).applicationPool
 # Recycle the application pool:
 Restart-WebAppPool $pool 

Don't know what I am missing here 

A:

# Load IIS module:
Import-Module WebAdministration
# Adds registered Microsoft SharePoint PowerShell snap-ins
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
# Get SharePoint Web Application
$app = Get-SPWebApplication http://site/
# Get pool name from web application:
$poolName = $app.ApplicationPool.Name
# Recycle the application pool:
Restart-WebAppPool $poolName

