Skip to content

Instantly share code, notes, and snippets.

View adamdriscoll's full-sized avatar
:bowtie:

Adam Driscoll adamdriscoll

:bowtie:
View GitHub Profile
@adamdriscoll
adamdriscoll / Beep.ps1
Created March 21, 2016 20:52
Beeping Computer
## Invoke a Win32 P/Invoke call.
function Invoke-Win32([string] $dllName, [Type] $returnType,
[string] $methodName, [Type[]] $parameterTypes, [Object[]] $parameters)
{
## Begin to build the dynamic assembly
$domain = [AppDomain]::CurrentDomain
$name = New-Object Reflection.AssemblyName �PInvokeAssembly�
$assembly = $domain.DefineDynamicAssembly($name, �Run�)
$module = $assembly.DefineDynamicModule(�PInvokeModule�)
$type = $module.DefineType(�PInvokeType�, �Public,BeforeFieldInit�)
@adamdriscoll
adamdriscoll / error.txt
Created May 11, 2016 14:41
git-tfs error
git tfs -d clone http://myServer:8080/tfs/myProject '$/Donor/Online Registration/Main' . --branches=auto
Looking for changeset 22351 in git repository...
=> Commit not found!
Looking for root changeset for branch:$/Donor/Online Registration/Dev/Dev1
Looking to find branch '$/Donor/Online Registration/Dev/Dev1' in all TFS branches...
Looking for all branches...
Found parent branch : $/Donor/Online Registration/Main
Cleaning...
Sep.Git.Tfs.Core.GitTfsException: error: a problem occurred when trying to clone the repository. Try to solve the proble
@adamdriscoll
adamdriscoll / TFSIssue.ps1
Created May 13, 2016 13:08
GetWorkItemLinkChanges
[Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\qyqpnmw4.vsi\Microsoft.TeamFoundation.Client.dll')
[Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\qyqpnmw4.vsi\Microsoft.TeamFoundation.VersionControl.Client.dll')
[Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\qyqpnmw4.vsi\Microsoft.TeamFoundation.WorkItemtracking.Client.dll')
[Reflection.Assembly]::LoadFrom('C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\qyqpnmw4.vsi\Microsoft.TeamFoundation.WorkItemtracking.Proxy.dll')
$m_srv = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection('https://btmtestmigration.visualstudio.com');
$m_srv.EnsureAuthenticated()
$WIStore = $m_srv.GetService([Microsoft.TeamFoundation.WorkItemTracking.Proxy.WorkItemServer])
$WIStore.GetWorkItemLinkChanges([Guid]::NewGuid()
@adamdriscoll
adamdriscoll / Branch.xml
Created June 10, 2016 15:00
TFS BranchObject from XML
<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><QueryBranchObjectsResponse xmlns="http://schemas.microsoft.com/TeamFoundation/2005/06/VersionControl/ClientServices/03"><QueryBranchObjectsResult><BranchObject><Properties><RootItem it="$/SystemCenter/Main" ctype="8"><Version xsi:type="ChangesetVersionSpec" cs="7861" /></RootItem><Description>Converted to Branch after Code given by Adam</Description><Owner>adam@driscoll.com</Owner><OwnerDisplayName>Adam Driscoll</OwnerDisplayName><OwnerUniqueName>adam@driscoll.com</OwnerUniqueName><BranchMappings /></Properties><DateCreated>2014-12-17T15:48:34.037Z</DateCreated><ChildBranches /><RelatedBranches /></BranchObject></QueryBranchObjectsResult></QueryBranchObjectsResponse></soap:Body></soap:Envelope>
@adamdriscoll
adamdriscoll / Properties.ps1
Last active June 10, 2016 15:32
Properties are just methods
#Backing methods
[System.Collections.ArrayList].GetMethods() | Where Name -like 'get_*' | Select Name
[System.Collections.ArrayList].GetMethods() | Where Name -like 'set_*' | Select Name
$ArrayList = New-Object System.Collections.ArrayList
$ArrayList.Add(1) | Out-Null
$ArrayList.Add(2) | Out-Null
#Indexer (parameterized property)
$ArrayList[1]
@adamdriscoll
adamdriscoll / TfsToVsts.ps1
Created June 20, 2016 21:15
Converts a TFVC repo to Git and creates the necessary Git repo in VSTS and uploads the Git repo
#This uses git-tfs and the PowerShell VSTS module
function ConvertTo-GitRepository {
param($Name, $Folder, $VstsUser, $VstsToken, $VstsAccountName, $VstsProjectName)
git tfs clone https://$VstsAccountName.visualstudio.com/defaultcollection $/$VstsProjectName/$Folder --branches=none
Push-Location (Split-Path $Folder -Leaf)
$ProjectId = Get-VstsProject -AccountName $VstsAccountName -User $VstsUser -Token $VstsToken | Where Name -eq $VstsProjectName | Select -Expand Id
@adamdriscoll
adamdriscoll / FindSetAlias.ps1
Last active July 1, 2016 02:21
Finds aliases set by Set-Alias
$Ast = {
Set-Alias -Name Test -Value SomeValue
New-Alias -Name SomeOtherAlias -Value SomeValue
}.Ast
$SetAliasCommands = $Ast.FindAll({$args[0] -is [System.Management.Automation.Language.CommandAst] -and ($Command.CommandElements[0].Value -eq 'Set-Alias' -or $Command.CommandElements[0].Value -eq 'New-Alias')}, $true)
foreach($SetAliasCommand in $SetAliasCommands)
{
$NextElementIsNameValue = $false
@adamdriscoll
adamdriscoll / New-Detour.ps1
Created July 28, 2016 17:45
Example of how to use EasyHook with powershell to override GetSystemTimeAsFileTime
function New-Detour
{
param(
$Library,
$FunctionName,
[ScriptBlock]$Detour,
[String[]]$ReferencedAssemblies
)
#Download from easyhook.codeplex.com
@adamdriscoll
adamdriscoll / MongoDBGuid.cs
Created February 7, 2017 03:07
MongoDBGuid
static Repository()
{
BsonClassMap.RegisterClassMap<Model>(cm => {
cm.AutoMap();
cm.SetIdMember(cm.GetMemberMap(c => c.Id));
cm.IdMemberMap.SetIdGenerator(CombGuidGenerator.Instance);
});
}
@adamdriscoll
adamdriscoll / SetSystemDate.cs
Created February 8, 2017 14:25
SetSystemDate
public void SetSystemDate(Domain domain, DateTime dateTime)
{
var connectionOptions = new ConnectionOptions();
connectionOptions.Username = domain.UserName;
connectionOptions.Password = domain.Password;
connectionOptions.EnablePrivileges = true;
connectionOptions.Authentication = AuthenticationLevel.PacketPrivacy;
connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
var offset = TimeZoneInfo.Local.GetUtcOffset(dateTime);
var minuteOffset = $"{Math.Round(offset.TotalMinutes):000}";