Skip to content

Instantly share code, notes, and snippets.

View JohnLBevan's full-sized avatar
🏠
Working from home

John Bevan JohnLBevan

🏠
Working from home
View GitHub Profile
@JohnLBevan
JohnLBevan / Convert-ToSimpleBacPac.ps1
Last active August 3, 2018 14:47
Remove unsupported content from bacpac/dacpac files, to allow them to be loaded in older versions of SQL
function New-TemporaryDirectory {
[CmdletBinding()]
Param ()
Process {
[string]$path = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath ([System.Guid]::NewGuid())
New-Item -ItemType Directory -Path $path
}
}
function Update-BacPacChecksum {
@JohnLBevan
JohnLBevan / Convert-LdapDateTime.ps1
Last active June 1, 2018 14:15
Calculate LDAP DateTime from FileTime
#Get-aduser myUsername -Properties lastlogondate, lastlogon, lastlogontimestamp | select lastlogondate, lastlogon, lastlogontimestamp
#LastLogonDate is a DateTime
#LastLogon is a Long / Int64
#LastLogonTimestamp is a Long / Int64
#NB: values may differ slightly, as LastLogonDate/LastLogonTimestamp is cached for up to 2 weeks before replicating to all servers, whilst LastLogon is updated instantly but only on the users logon server: https://serverfault.com/a/734641/137255
$lastLogonTimeLdap = 131723288263417819
#The official way
[DateTime]::FromFileTimeUtc($lastLogonTimeLdap)
--before running the below code, ensure you've set up a linked server per notes here: https://blog.sqlauthority.com/2016/03/30/sql-server-query-active-directory-data-using-adsi-ldap-linked-server/
declare @pageSize bigint = 900
, @usnMax bigint = 0
, @usnMaxPrevious bigint = -1
, @ldapPath nvarchar(max) = 'LDAP://myDomain.myForest.myCompany.com/DC=myDomain,DC=myForest,DC=myCompany,DC=com'
, @columnList nvarchar(max)
, @dynamicSql nvarchar(max)
, @dynamicSqlTemplate nvarchar(max) = '
INSERT INTO #PagedAdsi (@columnList)
@JohnLBevan
JohnLBevan / Compare-ObjectProperties.ps1
Last active May 30, 2018 10:34
List the properties of 2 objects side by side for comparison
function Compare-ObjectProperties {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true)]
$InputObject
,
[Parameter(Mandatory = $true)]
$CompareObject
)
Process {
@JohnLBevan
JohnLBevan / Get-LdapAttributeInfo.ps1
Last active October 29, 2025 09:25
Fetch all attributes info from https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx; allowing us to find fields by their ldap display name rather than their CN.
function Get-LdapAttributeInfo {
[CmdletBinding()]
Param ()
Process {
$pages = [xml](Invoke-RestMethod -Method Get -Uri 'https://msdn.microsoft.com/en-us/library/ms675090(v=vs.85).aspx' -UseBasicParsing -UseDefaultCredentials) #lists all AD attributes
[System.Xml.XmlNamespaceManager] $nsMgr = New-Object -TypeName System.Xml.XmlNamespaceManager($pages.NameTable)
$nsMgr.AddNamespace('ns','http://www.w3.org/1999/xhtml')
$pages.SelectNodes("/ns:html/ns:body/ns:div[@id = 'page']/ns:div[@id = 'body']/ns:div[@id = 'content']/ns:div[@class = 'topic']/ns:div[@id = 'mainSection']/ns:dl/ns:dd/ns:a/@href",$nsMgr) | select -ExpandProperty Value | %{
$result = [pscustomobject]@{
Documentation = $_
@JohnLBevan
JohnLBevan / Get-VstsCost.ps1
Last active May 25, 2018 11:13
Excel Spreadsheet Formulas to Calculate Pricing for N users based on tiers from https://www.visualstudio.com/team-services/pricing / additional info from https://marketplace.visualstudio.com/items?itemName=ms.vss-vstsuser
Function Get-VstsCost {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[ValidateRange(0,1000)]
[Int]$NoOfUsers
)
Begin {
# data from: https://www.visualstudio.com/team-services/pricing/
$Tiers = @{
function ConvertTo-QueryString {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[Hashtable]$Parameters
)
Process {
($Parameters.Keys | %{"$_=$($Parameters[$_])"}) -join '&'
}
}
Clear-Host
function Extract-XPaths {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
[System.Xml.XmlElement]$elem
)
Process {
[string]$name = $elem.LocalName
$name
@JohnLBevan
JohnLBevan / Cards.cs
Last active May 10, 2018 19:13
c-sharp-array-to-create-a-deck-of-cards (Answer to Stack Overflow Question 50278559)
//Question: https://stackoverflow.com/q/50278559/361842
//Fiddle: https://dotnetfiddle.net/26rxWs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
//consider using classes with public static members instead of enums if you want to add any functionality over Suits or Titles: https://stackoverflow.com/a/12675874/361842
public enum Suit
{
@JohnLBevan
JohnLBevan / PrepareHotfixPackageBundle.bat
Last active May 2, 2018 11:40
Notes on installing a package for DFO365
::Package Installation Instructions per: https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/migration-upgrade/install-metadata-hotfix-package
::Source Control Configuration per: https://docs.microsoft.com/en-us/dynamics365/unified-operations/dev-itpro/dev-tools/version-control-metadata-navigation#map-your-visual-studio-team-services-project-to-your-local-model-store-and-projects-folder
::Related discussion: https://community.dynamics.com/ax/f/33/t/229735
pushd "K:\AosService\PackagesLocalDirectory\Bin"
SCDPBundleInstall.exe -prepare -packagepath="C:\XppPackages\HotfixPackageBundle.axscdppkg" -metadatastorepath="K:\AosService\PackagesLocalDirectory\Metadata" -tfsworkspacepath="K:\AosService\PackagesLocalDirectory\Metadata" -tfsprojecturi="https://mytenant.visualstudio.com"
::NB: The TFSWorkspace path points to the METADATA (i.e. is the same as we used for metadatastorepath); not the PROJECT (e.g. C:\Users\User123abcdef\Documents\Visual Studio 2015\Projects)