Skip to content

Instantly share code, notes, and snippets.

View norman-bauer's full-sized avatar

Norman Bauer norman-bauer

View GitHub Profile
@norman-bauer
norman-bauer / Configure-SendAsPermissions.ps1
Last active April 13, 2018 07:21
Configure SendAs Permissions on an Office365 Distribution Group using PowerShell
Set-ExecutionPolicy RemoteSigned
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell/ -Credential $UserCredential -Authentication Basic -AllowRedirection
Import-PSSession $Session
$DistributionGroup = "somerandomdistributiongroup@normanbauer.com"
@norman-bauer
norman-bauer / GetSqlSids.sql
Last active April 13, 2018 07:21
Get all SIDs from SQL Server
use master
go
select sid, name, dbname from syslogins
@norman-bauer
norman-bauer / CreateSqlUserWithSid.sql
Created April 13, 2018 06:26
Create SQL User with given SID
create login your_sql_loginname with password = 'your_sql_loginspassword', sid = {your_sql_user_sid}
@norman-bauer
norman-bauer / SetUserAccountPictureFromAD.vbs
Last active April 13, 2018 07:20
How to display Active Directory stored user account pictures in Windows?
Function LoadPictureFromAD(szADsPath, szSaveFileName)
Dim objUser, bytesRead, adoStreamWrite
Const adTypeBinary = 1, adSaveCreateOverWrite = 2
Set objUser = GetObject(szADsPath)
bytesRead = objUser.Get("thumbnailPhoto")
Set adoStreamWrite = CreateObject("ADODB.Stream")
adoStreamWrite.Type = adTypeBinary
adoStreamWrite.Open
@norman-bauer
norman-bauer / UserAccountPicture.cs
Created April 13, 2018 06:36
UserAccountPicture.exe C# version
using System;
using System.Runtime.InteropServices;
namespace useraccountpicture
{
class Program
{
[DllImport("shell32.dll", EntryPoint = "#262", CharSet = CharSet.Unicode, PreserveSig = false)]
public static extern void SetUserTile(string username, int notneeded, string picturefilename);
@norman-bauer
norman-bauer / UserAccountPicture.vb
Created April 13, 2018 06:37
UserAccountPicture.exe VB.Net version
Imports System.Runtime.InteropServices
Module useraccountpicture
<DllImport("shell32.dll", EntryPoint:="#262", CharSet:=CharSet.Unicode, PreserveSig:=False)> _
Private Sub SetUserTile(ByVal username As String, ByVal notneeded As Integer, ByVal picturefilename As String)
End Sub
Sub Main(ByVal args As String())
If (args.Length = 2) Then
@norman-bauer
norman-bauer / SavePictureToAdFromUrl.vbs
Last active April 13, 2018 07:20
Upload a user picture from url to Active Directory with vbScript.
Function SavePictureToAdFromUrl(szADsPath, szUrl)
Dim objUser, bytesRead, adoStreamRead
Const adTypeBinary = 1
Set xml = CreateObject("Microsoft.XMLHTTP")
xml.Open "GET", szUrl, False
xml.Send
If xml.status = 200 Then
Set adoStreamRead = CreateObject("ADODB.Stream")
@norman-bauer
norman-bauer / SavePictureToAD.vbs
Last active April 13, 2018 07:20
Upload a user picture from file to Active Directory with vbScript.
Function SavePictureToAD(szADsPath, szLoadFileName)
Dim objUser, bytesRead, adoStreamRead
Const adTypeBinary = 1
Set adoStreamRead = CreateObject("ADODB.Stream")
adoStreamRead.Type = adTypeBinary
adoStreamRead.Open
adoStreamRead.LoadFromFile szLoadFileName
bytesRead = adoStreamRead.Read()
adoStreamRead.Close
@norman-bauer
norman-bauer / Configure-DHCPOption119OnScope.ps1
Last active December 31, 2022 08:24
Asks for a list of semicolon separated domain suffixes and a Windows Server DHCP Scope Id on which Option 119 will be configured accordingly
$domainSearchList = Read-Host "Please enter a list of domain suffixes separated by semicolons (e.g. domain.local;domain.tld;int.domain.tld)"
$scopeToConfigure = Read-Host "Please enter the scope id of the scope to be configured (e.g. 192.168.1.0)"
$splittedDomainSearchList = $domainSearchList -split "\;"
$domainSearchListHexArray = @();
Foreach ($domain in $splittedDomainSearchList)
{
$splittedDomainParts = $domain -split "\."
Foreach ($domainPart in $splittedDomainParts)
$username = "typeusernamehere"
[datetime]::FromFileTime((Get-ADDomainController -Filter * | foreach {Get-ADUser $username -Properties LastLogon -Server $_.Name | select LastLogon} | Measure-Object -Property LastLogon -Maximum).Maximum)