Skip to content

Instantly share code, notes, and snippets.

Dave Green davegreen

Block or report user

Report or block davegreen

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@davegreen
davegreen / Get-Membership.ps1
Last active Dec 18, 2015
A quick function to get groups that the current user is a member of.
View Get-Membership.ps1
# Gets a list of groups that the user is a member of from the current Windows identity token.
# Param1: $domain - Boolean value. Return group names with domain or not.
# e.g. true = "BUILTIN\Authenticated Users", false = "Authenticated Users".
Function Get-Membership($domain)
{
$groups = @()
foreach ($group in [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups)
{
$grp = $group.Translate([System.Security.Principal.NTAccount]).ToString()
@davegreen
davegreen / Get-ADDate.ps1
Last active Dec 19, 2015
A function that can be passed a date from AD, such as the lastlogon attribute and returns a string of the date, or the string 'Never'.
View Get-ADDate.ps1
# Returns a date string based on an AD attribute (like lastlogon, or accountexpires).
# Param1: $addate - AD attribute date value.
Function Get-ADDate($addate)
{
Try
{
$formatteddate = [datetime]::FromFileTime($addate).Date.ToString()
}
Catch
View CheckAttribWritable.cs
/// <summary>
/// Gets the DirectoryEntry object of the LDAP distinguishedname passed in, using the current user credentials.
/// </summary>
/// <param name="path">A distinguishedname of the object you wish to get the DirectoryEntry for.</param>
/// <returns></returns>
private static DirectoryEntry GetDirectoryEntry(string path)
{
DirectoryEntry de = new DirectoryEntry();
de.Path = path;
de.AuthenticationType = AuthenticationTypes.Secure;
@davegreen
davegreen / UPN.ps1
Created May 29, 2014
Quick one-liner for setting UPNs for users to match their email address (useful for working with Azure, O365, etc.)
View UPN.ps1
#Set UPN for all users with mobile phone numbers to email address
Get-ADuser -Filter * -Properties mobilephone, mail | where {$_.mobilephone -and $_.mail -ne $_.userPrincipalName} | ForEach-Object {Set-ADuser -Identity $_.ObjectGUID -UserPrincipalName $_.mail}
#Set UPN for all users to email address
Get-ADuser -Filter * -Properties mail | where {$_.mail -ne $_.userPrincipalName} | ForEach-Object {Set-ADuser -Identity $_.ObjectGUID -UserPrincipalName $_.mail}
@davegreen
davegreen / sharedsettings.cs
Last active Aug 29, 2015
A basic class for shared settings, allowing a key/value based settings file to be created or loaded, Lines starting with a # are used as comment lines and are ignored as settings. As an example, the class can be instantiated with: private SharedSettings sharedsettings = new SharedSettings("Contoso", "Test.cfg");
View sharedsettings.cs
/// <summary>
/// The shared settings class, responsible for reading and writing machine-wide shared settings.
/// </summary>
public class SharedSettings
{
/// <summary>
/// The file path to the shared settings file, computed using the common application data folder for wider OS support.
/// </summary>
private string sharedSettingsPath;
@davegreen
davegreen / OSDComputerName.ps1
Last active Apr 12, 2019
Altered script from http://www.scconfigmgr.com/2013/10/02/prompt-for-computer-name-during-osd-with-powershell/ to improve computer name validation - Originally by Nickolaj
View OSDComputerName.ps1
Function Load-Form
{
$Form.Controls.Add($TBComputerName)
$Form.Controls.Add($GBComputerName)
$Form.Controls.Add($ButtonOK)
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
}
Function Set-OSDComputerName
@davegreen
davegreen / ProBook6x70bConfig.cmd
Last active Aug 29, 2015
BIOS configuration command file for running the correct copy of HPs BiosConfigUtility with a hardcoded configuration file. This will be changed to support params..
View ProBook6x70bConfig.cmd
pushd %~dp0
set _bcu=BiosConfigUtility.exe
if /I "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" set _bcu=BiosConfigUtility64.exe
"%_bcu%" /nspwdfile:"%~dp0BIOSPW.bin" /set:"%~dp0ProBook6470bConfig.cfg"
IF %ERRORLEVEL% NEQ 0 "%_bcu%" /cspwdfile:"%~dp0BIOSPW.bin" /set:"%~dp0ProBook6470bConfig.cfg"
popd
@davegreen
davegreen / Get-ComputerADSite.ps1
Last active Feb 2, 2016
A function that will return the AD site the local computer is currently connected to. Useful for PowerShell login scripts that need to target specific sites.
View Get-ComputerADSite.ps1
Function Get-ComputerADSite()
{
<#
.Synopsis
Get the computers current AD site from the computer Netlogon information.
.Example
Get-ComputerADSite
.Notes
@davegreen
davegreen / Timezone.ps1
Last active Sep 26, 2015
Get and set the computer timezone.
View Timezone.ps1
#Requires -Version 3
Function Get-TimezoneFromOffset()
{
<#
.Synopsis
A function that gets the timezones that match a particular offset from UTC
.Parameter UTCOffset
A string containing offset time you require. This must match the form +NN:NN or -NN:NN.
@davegreen
davegreen / Connect-ExchangeOnline.ps1
Last active Apr 12, 2018
Function for connecting to an Exchange Online session. Useful in a PowerShell profile script.
View Connect-ExchangeOnline.ps1
function Connect-ExchangeOnline {
<#
.Synopsis
A function that connects to the Exchange online system.
.Parameter Credential
A credential object with rights to connect to the Exchange server. This parameter is mandatory.
.Parameter AllowClobber
Boolean value of whether the imported session will clobber existing commands. Defaults to True.
You can’t perform that action at this time.