Silent install IIS UrlRewrite and ARR by #PowerShell

Create-Item c:/msi -Type Directory
Invoke-WebRequest 'http://download.microsoft.com/download/C/F/F/CFF3A0B8-99D4-41A2-AE1A-496C08BEB904/WebPlatformInstaller_amd64_en-US.msi' -OutFile c:/msi/WebPlatformInstaller_amd64_en-US.msi
Start-Process 'c:/msi/WebPlatformInstaller_amd64_en-US.msi' '/qn' -PassThru | Wait-Process
cd 'C:/Program Files/Microsoft/Web Platform Installer'; .\WebpiCmd.exe /Install /Products:'UrlRewrite2,ARRv3_0' /AcceptEULA /Log:c:/msi/WebpiCmd.log

Howto rename Lotus Notes field by using PowerShell

You need to have Lotus Notes client installed on your machine. Then you need to run PowerShell (x86).

$lns = New-Object -ComObject Lotus.NotesSession
$lns.Initialize()
$db= $lns.GetDatabase('','YOUR_DB_NAME')

$doc = $db.GetDocumentByUNID('1E733555DDB27DA785257D7E005E64B0')
$doc.RemoveItem('TARGET_FIELD_NAME')
$doc.CopyItem($doc.GetFirstItem('SOURCE_FIELD_NAME'),'TARGET_FIELD_NAME')
$doc.RemoveItem('SOURCE_FIELD_NAME')
$doc.Save($false, $true)

Howto disable hotlinking for your AWS S3 resources

It is good idea to serve static content (e.g. images, video, …., not a JavaScript files) on AWS S3 instead of from your AWS EC2 server. In this case you reduce the workload on your web application.

The problem is that AWS S3 resources are not available for public by default.

The simple stupid solution is to make them all publicly available.

But what if we are talking about protected Web application where clients should enter credentials first to access the application. And one of the requirement is that all data should be not easily available! E.g. shouldn’t be referenced by other sites (hotlinking) or crawled by the search engines.

AWS S3 for everyone doesn’t work here.

Fortunately you can create the AWS S3 bucket policy which will allows to access the resources only for the particular referrers:

{
 "Version": "2008-10-17",
   "Id": "Vlasenko Access",
   "Statement": [
   {
     "Sid": "AllowPublicRead",
     "Effect": "Allow",
     "Principal": {
       "AWS": "*"
     },
     "Action": "s3:GetObject",
     "Resource": "arn:aws:s3:::TestPolicy/*",
     "Condition": {
       "StringLike": {
         "aws:Referer": [
           "https://vlasenko.org/*",
           "http://vlasenko.guru/*",
           "http://vlasenko.ninja/*"
         ]
       }
     }
   }
 ]
}


The image above available only trough this blog post. Try to copy the URL and paste it into a new tab in your browser. Don’t use Open link in new Tab!

#SQL: Update xml field from value from other table

We are going to update Title field in XML below. Assume we have incorrect values there in our Library table. We will find the correct values by using Title field from AllBooks table.

<Book xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <Title>Incorrect Title</Title>
</Book>
UPDATE Library SET info.modify('replace value of (/Book/Title/text())[1] with sql:column("Title")')
FROM Library 
LEFT OUTER JOIN AllBooks ON Library.BookID=AllBooks .ID
WHERE info.value('data((/Book/Title)[1])','nvarchar(max)') like 'Incorrect Title%'