Skip to content

Instantly share code, notes, and snippets.

View lazywinadmin's full-sized avatar

François-Xavier Cat lazywinadmin

View GitHub Profile
#http://www.lazywinadmin.com/2013/10/powershell-get-domainuser.html
function Get-DomainUser {
PARAM($DisplayName)
$Search = [adsisearcher]"(&(objectCategory=person)(objectClass=User)(displayname=$DisplayName))"
foreach ($user in $($Search.FindAll())){
New-Object -TypeName PSObject -Property @{
"DisplayName" = $user.properties.displayname -as [string]
"UserName" = $user.properties.samaccountname -as [string]
"Description" = $user.properties.description -as [string]
#http://www.lazywinadmin.com/2013/10/powershell-get-domainuser.html
function Get-DomainUser {
PARAM($DisplayName)
$Search = [adsisearcher]"(&(objectCategory=person)(objectClass=User)(displayname=$DisplayName))"
foreach ($user in $($Search.FindAll())){
New-Object -TypeName PSObject -Property @{
"DisplayName" = $user.properties.displayname -as [string]
"UserName" = $user.properties.samaccountname -as [string]
"Description" = $user.properties.description -as [string]
@lazywinadmin
lazywinadmin / getdomainuser_phonenumber3.ps1
Created May 17, 2014 16:54
getdomainuser_phonenumber3.ps1
function Get-DomainUser
{
PARAM ($DisplayName,[Adsi]$SearchRoot= "LDAP://OU=Servers,OU=TEST,dc=fx,dc=lab")
$Search = [adsisearcher]"(&(objectCategory=person)(objectClass=User)(displayname=$DisplayName))"
$Search.searchRoot = $SearchRoot
foreach ($user in $($Search.FindAll()))
{
New-Object -TypeName PSObject -Property @{
"DisplayName" = $user.properties.displayname -as [string]
"UserName" = $user.properties.samaccountname -as [string]
@lazywinadmin
lazywinadmin / Get-NestedMember.ps1
Created October 22, 2014 02:43
Get-NestedMember
function Get-NestedMember
{
<#
.SYNOPSIS
Find all Nested members of a group
.DESCRIPTION
Find all Nested members of a group
.PARAMETER GroupName
Specify one or more GroupName to audit
.Example
@lazywinadmin
lazywinadmin / Vmware_Hosts_VIB.ps1
Last active August 29, 2015 14:10
Get the VIB information of VMware Hosts
Get-VMHost | Where-Object { $_.ConnectionState -eq “Connected” } | Foreach-Object {
$CurrentVMhost = $_
TRY
{
# Exposes the ESX CLI functionality of the current host
$ESXCLI = Get-EsxCli -VMHost $CurrentVMhost.name
# Retrieve Vib with name 'net-e1000e'
$ESXCLI.software.vib.list() | Where-object { $_.Name -eq "net-e1000e" } |
FOREACH
{
#Source: Reddit (http://www.reddit.com/r/PowerShell/comments/2oqk4k/using_validateset_with_exceptions/)
function test {
# You have to use cmdletbinding for the dynamic parameter to work
[CmdletBinding()]
Param()
# The cool thing about this is that you can actually get really good tab completion / intellisense from doing it this way...
DynamicParam
{
[string[]]$ValidServices = get-content $PSScriptRoot\services.txt
@lazywinadmin
lazywinadmin / Get-Uptime.ps1
Created December 12, 2014 15:43
Smart way to get the uptime on a local machine
function Get-Uptime
{
$millisec = [Environment]::TickCount
[Timespan]::FromMilliseconds($millisec)
}
@lazywinadmin
lazywinadmin / ForEach-Parallel.ps1
Created December 22, 2014 23:51
Execute parallel powershell thread using runspace objects
function ForEach-Parallel
{
<#
.DESCRIPTION
.SYNOPSIS
.NOTES
Source: http://powertoe.wordpress.com/2012/05/03/foreach-parallel/
.EXAMPLE
(0..50) |ForEach-Parallel -MaxThreads 4{
$_
@lazywinadmin
lazywinadmin / [Ipaddress].ps1
Last active August 29, 2015 14:12
Smart way to convert string to ipaddress data
"::1" -as [ipaddress] | fl * -Force
IPAddressToString : ::1
Address :
AddressFamily : InterNetworkV6
ScopeId : 0
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IsIPv6Teredo : False
@lazywinadmin
lazywinadmin / Get-MyUptime.ps1
Created December 30, 2014 18:21
Get Uptime of remote computers
# Jeff Hicks
# http://www.petri.com/creating-advance-functions-powershell.htm?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+Petri+%28Petri+IT+Knowledgebase%29
Function Get-MyUptime {
[cmdletbinding()]
Param(
[Parameter(Position=0,ValueFromPipeline,ValueFromPipelineByPropertyName)]
[ValidateNotNullorEmpty()]
[Alias("cn","host")]
[string[]]$Computername = $env:Computername