function retBase64Image($path){
$newImg = [convert]::ToBase64String((get-content $path -encoding byte))
$ext = gci $path | select @{Name="Ext";Expression={$_.Extension.substring(1)}} | select -ExpandProperty Ext
Write-Host "style='background:url(data:image/$ext;base64,$newImg) right bottom no-repeat'"
Write-Host "<img src='data:image/$ext;base64,$newImg' />"
}
retBase64Image -path "C:\MyImages\Image1.gif"
Monday, 24 September 2012
Found some useful code to assist with embedding images as Base64. Outputs element style tag as well as image element:
Friday, 21 September 2012
Nice little one liner to return all the links from a webpage:
"http://www.google.com" | %{([regex]"<a.*?href=[""'](?<url>[^""^']+[.]*?)[""'].*?>(?<keywords>[^<]+[.]*?)</a>").Matches((new-object system.Net.WebClient).DownloadString($_)) | select @{Name="text";Expression={$_.Groups[2].Value.trim()}}, @{Name="href";Expression={$tmpVal = $_.Groups[1].Value.trim();if ($tmpVal.startswith("http")){$tmpVal}else{$url+$tmpVal}}}}
Wednesday, 12 September 2012
Powershell to delete remote virtual directory on an IIS 6.0 (Windows 2003) server (in default web site):
function delete-vDir(){
param(
[parameter(Mandatory = $true)][string] $vDirName,
[parameter(Mandatory = $true)][string] $iisServer
)
gwmi -namespace "root\MicrosoftIISv2" -class "IISWebVirtualDir" -filter "Name = 'W3SVC/1/ROOT/$vDirName'" -ComputerName $iisServer -Authentication PacketPrivacy | %{Write-Host "Deleting vDir $vDirName on $iisServer";$_.Delete()}
}
Subscribe to:
Comments (Atom)