Skip to content

Instantly share code, notes, and snippets.

View sayedihashimi's full-sized avatar

Sayed Ibrahim Hashimi sayedihashimi

View GitHub Profile
@sayedihashimi
sayedihashimi / add-function-with-param.ps1
Created February 3, 2014 05:57
PowerShell: Add a function with a parameter to an object
$result | Add-Member -MemberType ScriptMethod ExpandString -Value {
[cmdletbinding()]
param(
[Parameter(
Mandatory=$true)]
[string]
$unexpandedValue
)
process{
if($this.ProjectInstance){
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir Condition=" '$(OutDir)'=='' ">$(MSBuildThisFileDirectory)bin\</OutDir>
<Configuration Condition=" '$(Configuration)'=='' ">Release</Configuration>
<SourceHome Condition=" '$(SourceHome)'=='' ">$(MSBuildThisFileDirectory)src\</SourceHome>
<ToolsHome Condition=" '$(ToolsHome)'=='' ">$(MSBuildThisFileDirectory)tools\</ToolsHome>
@sayedihashimi
sayedihashimi / xml-module-ps4.psm1
Created March 30, 2014 21:46
XML DSL module by Joel Bennett updated for PowerShell 4
# original by JOEL 'JAYKUL' BENNETT http://huddledmasses.org/a-dsl-for-xml-in-powershell-new-xdocument/
# modified by Sayed Ibrahim Hashimi for PowerShell 4
# Improves over the built-in Select-XML by leveraging Remove-XmlNamespace http`://poshcode.org/1492
# to provide a -RemoveNamespace parameter -- if it's supplied, all of the namespace declarations
# and prefixes are removed from all XML nodes (by an XSL transform) before searching.
# IMPORTANT: returned results *will not* have namespaces in them, even if the input XML did.
# Also, only raw XmlNodes are returned from this function, so the output isn't completely compatible
# with the built in Select-Xml. It's equivalent to using Select-Xml ... | Select-Object -Expand Node
@sayedihashimi
sayedihashimi / Display-MessageInForegroundColors.ps1
Last active August 29, 2015 13:58
Powershell display message in all foreground colors
function Display-MessageInForegroundColors {
[cmdletbinding()]
param(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
$message
)
process{
[enum]::getvalues([type]'ConsoleColor') | ForEach-Object{
$curForeground = $_
'{0}: {1}' -f $message,$curForeground | Write-Host -ForegroundColor $curForeground
@sayedihashimi
sayedihashimi / _webjob-env-vars.txt
Last active August 1, 2022 02:46
Environment variables when your app is running as a Microsoft Azure Web Job
ALLUSERSPROFILE C:\DWASFiles\Sites\WebjobsEnvvars\ProgramData
APP_POOL_CONFIG C:\DWASFiles\Sites\WebjobsEnvvars\Config\applicationhost.config
APP_POOL_ID WebjobsEnvvars
APPDATA C:\DWASFiles\Sites\WebjobsEnvvars\AppData
APPSETTING_REMOTEDEBUGGINGVERSION 11.0.611103.400
APPSETTING_ScmType None
APPSETTING_WEBSITE_NODE_DEFAULT_VERSION 0.10.29
APPSETTING_WEBSITE_SITE_NAME WebjobsEnvvars
aspnet:DisableFcnDaclRead true
aspnet:PortableCompilationOutput true
@sayedihashimi
sayedihashimi / get-image-optimizer.ps1
Last active August 29, 2015 14:03
Script which can be used to optimize images. All you need to do is download the script and call it. The script will download the files it needs to run.
function OptimizeImages{
[cmdletbinding()]
param(
$folder,
$force = $false,
$customTemp = "$env:LocalAppData\CustomPublish\",
$imgOptUrl = 'https://raw.githubusercontent.com/ligershark/AzureJobs/master/ImageCompressor.Job/optimize-images.ps1'
)
process{
if(!(Test-Path $customTemp)){New-Item $customTemp -ItemType Directory}
@sayedihashimi
sayedihashimi / getnuget.proj
Last active July 26, 2022 19:53
Samples showing how to download nuget in a scrpit to avoid checking it in
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="GetNuget">
<!--
This is an MSBuild snippet that can be used to download nuget to the path
in the property NuGetExePath property.
Usage:
1. Copy and paste this into your build script
2. Call the GetNuGet target before you use nuget.exe from $(NuGetExePath)
@sayedihashimi
sayedihashimi / transform-xml.ps1
Last active January 17, 2024 20:02
Script which can be used to transform an XML file using XDT. All you need to do is download the script and call it. The script will download the files it needs to run.
#!/usr/bin/env powershell
<#
.SYNOPSIS
You can use this script to easly transform any XML file using XDT.
To use this script you can just save it locally and execute it. The script
will download its dependencies automatically.
Created by sayediHashimi
Modified by obscurerichard
Thanks Stack Overflow: https://stackoverflow.com/questions/8989737/web-config-transforms-outside-of-microsoft-msbuild
@sayedihashimi
sayedihashimi / elapsed-time.proj
Created July 28, 2014 21:28
msbuild get elapsed time
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
This shows how you can calculate the elapsed time in MSBuild
-->
<Target Name="BeforeBuild">
<PropertyGroup>
<startTime>$([System.DateTime]::Now)</startTime>
@sayedihashimi
sayedihashimi / remove-items.ps1
Last active August 29, 2015 14:04
Uses MSBuild to remove items from the project file
[cmdletbinding()]
param(
[Parameter(
Mandatory=$true,
Position=0,
ValueFromPipeline=$true)]
$folder,
[bool]$backup = $true,