Skip to content

Instantly share code, notes, and snippets.

@NotNotWrongUsually
NotNotWrongUsually / who.ps1
Last active July 28, 2020 06:29
who function
<#
.SYNOPSIS
WHO Searches AD for user information.
.DESCRIPTION
If an exact account name is found it will be shown. If not a search will be performed. Fields searched are
sAMAccountName, Name, and Title
.PARAMETER Search
User to look for in AD.
.PARAMETER RetrieveHostname
Get the hostname for the resolved user(s). More precisely: gets computer objects in AD whose description
@NotNotWrongUsually
NotNotWrongUsually / gist:7db8f3f7abd88a95868284652232b9af
Created October 6, 2019 11:50
Grab image from AD and rescale if desired
function UserPhoto ($user, [int]$width, [int]$height) {
$user_data = ([adsisearcher]"(&(objectClass=user)(sAMAccountName=$user))").FindAll()
$stream = [System.Io.MemoryStream]::new($user_data.Properties["thumbnailphoto"][0])
$img = [System.Drawing.Image]::FromStream($stream)
if ($width -or $height) {
if (-not $width) {
$width = ($img.Width / $img.height) * $height
}
# The below code is a somewhat modified version of original work from
# https://gist.github.com/idavis/856603/818f50f1d6d862ca5458e5b87bca034e567b387f
# All credit to the author.
function Invoke-AsOtherUser {
[CmdletBinding()]
param (
[parameter(Mandatory = $true)][PSCredential] $Credentials,
[parameter(Mandatory = $true)][ScriptBlock] $ScriptBlock
)