Showing posts with label IIS. Show all posts
Showing posts with label IIS. Show all posts

Thursday, December 20, 2018

CertAuto

For a developer environment I had a few certificates that needed automatic renewal at certain intervals. The script below uses the PSPKI module to check if certificates are expiring on IIS-Site in X days and if so, renews the agains a local certification authority.
The PSPKI -module is really god for sending and approving certification requests  via Powershell when Microsofts own tools leaves room for improvement.

This is really only for a testenviroment and offline-enviroments.
Folder structure needs to created to look below




Certini contains the template for the certificate like below for example
 [Version]
Signature = "$Windows NT$"
[NewRequest]
Subject = "C=US,S=CA,L=OHIO,O=Fabrikam,OU=IT,CN=ajax.aspnetcdn.com"
Exportable = TRUE
KeyLength = 4096
KeySpec = 1
KeyUsage = 0xa0
MachineKeySet = True
ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
ProviderType = 12
Silent = True
SMIME = False
RequestType = PKCS10
FriendlyName = "ajax.aspnetcdn.com"



References:
https://www.sysadmins.lv/projects/pspki/default.aspx  - PSPKI Module

Monday, June 04, 2018

Export IIS bindings

I find the cmdlet for exporting cmdlets a bit lacking so I built my own export function for fun and profit.
The function in the toolsfile collects all info and return a populated object that can be used to export list to file or do something else with.

Wednesday, December 20, 2017

Remove iislogs

Built a nice script to remove older files from IISLogs.
It has two retentionmodes. Either clear based on number of last changed files or for specific days.

Thursday, July 21, 2016

Script for updating URLrewrite-rules

In these days urlrewrite might not be the first choice for using but I had a situationen where i needed to be applied.
This offered an oppertunity to create a script to automate the addition of custom rules sets for a specific file.
And I got to fiddle with xml-manipulation which is also fun.
This script reads an csv for inputaddress and ruleTemplate file
csv – addresses.csv
ruleName,target,destination
tomteland,www.tomteland.se,tomteland

Powershellscript, this script reads web.config from designated place makes a copy to $workingDir where updates are applied to file in $workingDir. This a pretty specific script, for example outboundRules are applied before <precondition>-tagg, but haven’t really experimented what happens if the preconditions aren’t there for example. So better to use as inspiration rather than copy paste. Also rewriteRules will need to be adjusted for your particuliar scenarios. Matching for rules to change are made with replace() towards #rulename#, #destination and #target# cause this was easier for this scenario.

Tuesday, July 07, 2015

IIS headers and powershell

Scenario: Have old IIS-site on a different server, need to get all headers for a site to new IIS-site on another server. I could’t find any easy way to do it via gui, but scripting was pretty easy using the builtin IIS cmdlets.
So export all headers to textfile, edit that one if you need, and the import on new server.

---------------ExportHeadersFromSite.ps1---------------------
$iisSite = "mysite"
$path = "C:\Scripts\IIS-HostHeaders\hostheaders_mysite.csv"
$mybindings = Get-WebBinding -Name $iisSite | select protocol,bindinginformation
foreach ($binding in $mybindings)
{
write-output "Adding protocol $($binding.protocol) with binding $($binding.bindinginformation)"
}
$mybindings | export-csv -Path $path -NoTypeInformation

--------------------eof-------------------------------------------------------

--------------AddBindingsFromFile.ps1------------------------
$myfilename = "hostheaders.csv"
$site = "myNewSite"
$importfile = "$(Split-Path -Parent $MyInvocation.MyCommand.Definition)\$myfilename"

import-csv $importfile -Delimiter "," |ForEach-Object {
try {
$hostheader = $_.bindinginformation | %{$_.split(':')[-1]}
New-WebBinding -Name $site -Protocol $_.protocol -HostHeader $hostheader
write-host -foregroundcolor green "Added $hostheader to $site with protocol $($_.protocol)"
}
catch {write-host -foreground yellow "Couldn't do it. Already there?" }

}
----------------------------------eof-----------------------------------------

Powershell and Uptimerobot

Uptimerobot can be quite tedious when you need to update many monitors at once. For example say you bought the license for Uptimerobot and n...