Skip to content

Instantly share code, notes, and snippets.

View jmelosegui's full-sized avatar

Juan Manuel Elosegui jmelosegui

View GitHub Profile
@jmelosegui
jmelosegui / GetLDAPUserInfo.ps1
Created March 1, 2018 13:27
The script will receive a path to a text file containing one GUID per line, loop over each line and search for the user info (Full Name) then generate a CSV file with the user info
param(
[Parameter(Mandatory=$true)]
$filePath
)
$accountsFilter= ""
Get-Content -Path $filePath | ForEach-Object {
if($_.Trim()){
$accountsFilter += "(sAMAccountName=$_)"
@jmelosegui
jmelosegui / Spy-Cmdlet.ps1
Created July 3, 2017 19:21
Reflect Powershell CmdLet using ICSharpCode ILSpy.
function Spy-Cmdlet {
param(
[Management.Automation.CommandInfo]$command
)
if ($input) {
trap { $_; break }
$command = $input | select -first 1
}
@jmelosegui
jmelosegui / Add-ChromeExtensions.ps1
Created June 28, 2017 18:04
Add extension to Chrome
[CmdletBinding()]
param()
Function Get-RegistryKeyPropertiesAndValues
{
Param(
[Parameter(Mandatory=$true)]
[string]$path
)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<!-- This will allow the config file to be copied to any project referencing the project that need the config transformation -->
<PropertyGroup>
<AllowedReferenceRelatedFileExtensions>
$(AllowedReferenceRelatedFileExtensions);
.dll.config
</AllowedReferenceRelatedFileExtensions>
-- Detect
sp_change_users_login 'report'
-- Repair
SELECT 'EXEC sp_change_users_login ''Update_One'', '''+[name]+''', '''+[name]+''''
FROM sys.database_principals WHERE
type_desc='SQL_USER'
and NAME NOT IN ('dbo','guest','INFORMATION_SCHEMA','sys')
@jmelosegui
jmelosegui / Odbccp32.cs
Created May 15, 2017 17:40
P/Invoke Odbccp32
public class Odbccp32
{
/// <summary>
/// From sql.h
/// </summary>
private const int SQL_MAX_MESSAGE_LENGTH = 512;
[DllImport(nameof(Odbccp32), CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SQLGetInstalledDrivers(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);
@jmelosegui
jmelosegui / Odbccp32.cs
Created May 15, 2017 17:40
P/Invoke Odbccp32
public class Odbccp32
{
/// <summary>
/// From sql.h
/// </summary>
private const int SQL_MAX_MESSAGE_LENGTH = 512;
[DllImport(nameof(Odbccp32), CharSet = CharSet.Unicode, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SQLGetInstalledDrivers(char[] lpszBuf, ushort cbufMax, out ushort pcbBufOut);
@jmelosegui
jmelosegui / Install-Npm.ps1
Created April 25, 2017 18:18
Install npm in the UserProfile Folder if it does not exist.
[CmdletBinding()]
param(
[switch]$force
)
$userProfileDir = $env:USERPROFILE
$NodeDir = Join-Path $userProfileDir "Node"
if($force -and (Test-Path $NodeDir)){
##-----------------------------------------------------------------------
## <copyright file="ApplyVersionToAssemblies.ps1">(c) Microsoft Corporation. This source is subject to the Microsoft Permissive License. See http://www.microsoft.com/resources/sharedsource/licensingbasics/sharedsourcelicenses.mspx. All other rights reserved.</copyright>
##-----------------------------------------------------------------------
# Look for a 0.0.0.0 pattern in the build number.
# If found use it to version the assemblies.
#
# For example, if the 'Build number format' build process parameter
# $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
# then your build numbers come out like this:
# "Build HelloWorld_2013.07.19.1"
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Input;
using static PInvoke.User32;
using static PInvoke.Kernel32;
namespace WpfApplication1
{