Skip to content

Instantly share code, notes, and snippets.

View nordineb's full-sized avatar

Nordine Ben Bachir nordineb

View GitHub Profile
###
### Without splatting
###
Get-Process -Name dns -ComputerName localhost
###
### With splatting
###
$myparamas = @{
@nordineb
nordineb / Invoke-WebApiWithAadToken.ps1
Created January 26, 2017 14:57 — forked from craig-martin/Invoke-WebApiWithAadToken.ps1
Use PowerShell to Authenticate to AAD Then Call a Web API
### Load ADAL
Add-Type -Path "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
# Set AAD client ID for the client app
$clientId = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"
$resourceAppIdURI = "https://TestWebApi01.azurewebsites.net"
$authority = "https://login.windows.net/MyAadDirectory.onmicrosoft.com"
# Create Authentication Context tied to Azure AD Tenant
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
@nordineb
nordineb / New-SelfSignedCert.ps1
Created January 26, 2017 14:57 — forked from craig-martin/New-SelfSignedCert.ps1
Create a Self-Signed Cert with PowerShell
#Create the cert
New-SelfSignedCertificate -DnsName 'foo.azurewebsites.net' -CertStoreLocation cert:\CurrentUser\My -KeyAlgorithm RSA -KeyLength 2048 -KeyExportPolicy Exportable #-KeyUsage DigitalSignature,nonRepudiation,keyEncipherment
#Look for the cert
dir Cert:\CurrentUser\My
#Export the cert to a PFX file
$mypwd = ConvertTo-SecureString -String "WhoFedTheDogCorn?" -Force –AsPlainText
dir Cert:\CurrentUser\My | Where Subject -EQ 'CN=foo.azurewebsites.net' | Export-PfxCertificate -ChainOption BuildChain -Password $mypwd -FilePath E:\Scratch\fooCert.pfx
@nordineb
nordineb / SHRINK DATABASE
Created May 10, 2017 15:32
REMINDER: SHRINK DATABASE
ALTER DATABASE MYDB SET RECOVERY SIMPLE
USE MYDB
DBCC SHRINKFILE ('MYDB_LOG', 1)
DBCC SHRINKFILE ('MYDB', 1)
@nordineb
nordineb / customerorders.usql
Last active May 15, 2022 07:46
USQL demo join
DECLARE @customerscsv string = "/Data/Meny/postgres_public_customer.csv";
DECLARE @orderlinescsv string = "/Data/Meny/postgres_public_order_line.csv";
DECLARE @productscsv string = "/Data/Meny/postgres_public_product.csv";
DECLARE @orderscsv string = "/Data/Meny/postgres_public_store_order.csv";
DECLARE @cvsout string = "/Data/Meny/Output/customerorders.csv";
@customers =
EXTRACT Id int,
FirstName string,
@nordineb
nordineb / simpleselect.usql
Last active May 15, 2022 07:46
simple select demo
DECLARE @inputfile string = "/Data/Meny/postgres_public_customer.csv";
DECLARE @cvsout string = "/Data/Meny/Output/ourcustomers.csv";
DECLARE @tsvout string = "/Data/Meny/Output/ourcustomers.tsv";
DECLARE @txtout string = "/Data/Meny/Output/ourcustomers.txt";
@customers =
EXTRACT UserId int,
FirstName string,
LastName string,
@nordineb
nordineb / subselect.usql
Last active May 15, 2022 07:47
subselect
DECLARE @inputfile string = "/Data/Meny/postgres_public_customer.csv";
DECLARE @cvsout string = "/Data/Meny/Output/ourcustomers2.csv";
DECLARE @tsvout string = "/Data/Meny/Output/ourcustomers2.tsv";
DECLARE @txtout string = "/Data/Meny/Output/ourcustomers2.txt";
@customers =
EXTRACT UserId int,
FirstName string,
LastName string,
Address string,
@nordineb
nordineb / top5buyers.usql
Last active May 15, 2022 07:47
top 5 buyers
DECLARE @customerordersinput string = "/Data/Meny/Output/customerorders.csv";
DECLARE @cvsout string = "/Data/Meny/Output/top5buyers.csv";
@customersorders =
EXTRACT CustomerId int,
CustomerFirstName string,
CustomerLastName string,
ProductName string,
ProductPrice int,
Function Test-DownloadUri {
<#
.SYNOPSIS
Tests that a url is valid
.DESCRIPTION
Returns a status code from an http request of a url. Used to verify that download links work.
.PARAMETER Uri
The url that we are checking is valid
.INPUTS
N/A
@nordineb
nordineb / curl-format.txt
Created October 9, 2017 09:07
cURL custom formatted output for timing of requests
\n
Timing information\n
==================\n
*time_appconnect The time it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed.\n
*time_connect The time it took from the start until the TCP connect to the remote host (or proxy) was completed.\n
*time_namelookup The time it took from the start until the name resolving was completed.\n
*time_pretransfer The time it took from the start until the file transfer was just about to begin.\n
*time_redirect The time it took for all redirection steps including name lookup, connect, pretransfer and transfer.\n
*time_starttransfer The time it took from the start until the first byte was just about to be transferred.\n
*time_total The total time that the full operation last\n