Skip to content

Instantly share code, notes, and snippets.

@ifrahim
ifrahim / IPRestrictIISSite
Created February 26, 2014 15:34
IP Restrict an IIS website using Powershell
# Restrict IIS website to be only accessible locally.
$SiteName = "MySiteName"
# secure site - Restrict IP
Set-WebConfigurationProperty -Filter /system.webserver/security/ipsecurity -Name allowUnlisted -Value $false -Location $SiteName
add-webconfiguration /system.webServer/security/ipSecurity -location $SiteName -value @{ipAddress="localhost";allowed="true"} -pspath IIS:\
@ifrahim
ifrahim / CreateIISSite
Created February 26, 2014 15:31
Create IIS Site using Powershell
# The following code will create an IIS site and it associated Application Pool.
# Please note that you will be required to run PS with elevated permissions.
# Visit http://ifrahimblog.wordpress.com/2014/02/26/run-powershell-elevated-permissions-import-iis-module/
# set-executionpolicy unrestricted
$SiteFolderPath = "C:\WebSite" # Website Folder
$SiteAppPool = "MyAppPool" # Application Pool Name
$SiteName = "MySite" # IIS Site Name
$SiteHostName = "www.MySite.com" # Host Header
@ifrahim
ifrahim / PSWithElevatedPermissions
Created February 26, 2014 15:25
Run PowerShell with elevated permissions (IIS Module)
# To run PowerShell with elevated permissions for IIS Module, run through the following steps
# Create a PowerShell shortcut and update its target path as:
# %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "import-module webadministration | out-null"
# This will import IIS Module in PowerShell enabling you to access IIS services
@ifrahim
ifrahim / Unpublish scheduled page in Umbraco using Razor
Created February 25, 2014 17:24
Unpublish scheduled page in Umbraco using Razor
@inherits umbraco.MacroEngines.DynamicNodeContext
@using umbraco.BusinessLogic;
@using umbraco.cms.businesslogic.web;
@{
var thisModel = @Model;
foreach (var page in thisModel.Children)
{
var doc = new Document(page.Id);
var publishAt = doc.ReleaseDate;
var removeAt = doc.ExpireDate;