Created
December 8, 2016 14:43
-
-
Save sdwheeler/15e226097358c7315e34cd9b7d7489e9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#region AD Functions | |
#------------------------------------------------------- | |
function get-servers { | |
param([string[]]$names, | |
[string[]]$props = @('DNSHostName','OperatingSystem') | |
) | |
foreach ($name in $names) { | |
$c = $null | |
$hostname = ($name -split '\.')[0] | |
$domain = $name.Substring($name.IndexOf('.')+1) | |
$dcparts = $domain -split '\.' | |
for ($x=0; $x -lt $dcparts.count; $x++) { $dcparts[$x]='dc={0}' -f $dcparts[$x] } | |
$searchbase = $dcparts -join ',' | |
$opts = @{ filter='Name -like "{0}"' -f $hostname; property='*'; server="$domain"; SearchBase="$searchbase"; } | |
$c = get-adcomputer @opts | |
if ($c.CN -ne '') { | |
$c | Select-Object $props | |
} else { | |
"$hostname ($name) - not found" | |
} | |
} | |
} | |
#------------------------------------------------------- | |
function get-kmsnames { | |
param([switch]$test) | |
$domains = get-adforest | Select-Object -exp domains | |
$list = $domains | %{ Resolve-DnsName -type SRV "_vlmcs._tcp.$_" } | |
if ($test) { | |
$list | %{ Test-NetConnection $_.NameTarget -Port $_.Port | | |
Select-Object ComputerName,RemoteAddress,RemotePort,PingSucceeded,TcpTestSucceeded | |
} | |
} else { | |
$list | |
} | |
} | |
#------------------------------------------------------- | |
function phone { | |
param([string[]]$names) | |
$users = $names | %{ Get-ADUser -identity $_ -prop sAMAccountName,DisplayName,telephonenumber,EmailAddress,physicalDeliveryOfficeName,title,mobile,department } | |
$users | Select-Object @{l='account';e={$_.sAMAccountName}}, | |
@{l='name';e={$_.DisplayName}}, | |
title, | |
department, | |
@{l='email';e={$_.EmailAddress}}, | |
@{l='phone';e={$_.telephonenumber}}, | |
@{l='mobile';e={$_.mobile}}, | |
@{l='office';e={$_.physicalDeliveryOfficeName}} | |
} | |
#------------------------------------------------------- | |
function get-aduserpic { | |
param($samname) | |
$user = Get-ADUser $samname -Properties thumbnailphoto | |
$user.thumbnailphoto | Set-Content .\$samname.jpg -Encoding byte | |
} | |
#------------------------------------------------------- | |
function set-aduserpic { | |
param($samname) | |
$photo = [byte[]](Get-Content .\$samname.jpg -Encoding byte) | |
Set-ADUser $samname -Replace @{thumbnailPhoto=$photo} | |
} | |
#------------------------------------------------------- | |
#endregion | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment