Skip to content

Commit

Permalink
initial code
Browse files Browse the repository at this point in the history
lipkau committed Jun 20, 2015
1 parent 2a0ef8a commit 7246404
Showing 44 changed files with 165 additions and 0 deletions.
Binary file added Functions/Add-GroupMember.ps1
Binary file not shown.
Binary file added Functions/Disable-Account.ps1
Binary file not shown.
Binary file added Functions/Enable-Account.ps1
Binary file not shown.
Binary file added Functions/Get-ADACL.ps1
Binary file not shown.
165 changes: 165 additions & 0 deletions Functions/Get-Computer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#Requires -Version 2.0
Function Get-Computer
{
<#
.Synopsis
Retrieves all computer objects in a domain or container.
.Description
Retrieves all computer objects in a domain or container.
.Notes
Author : Oliver Lipkau <[email protected]>
Blog : http://oliver.lipkau.net/blog/
Version : v1.3
Date : 2013-05-16 17:35:26
.Inputs
System.String
.Parameter Name
Value to search for in: sAMAccountName, cn, displayName, dNSHostName and name
.Parameter SearchRoot
A search base (the distinguished name of the search base object) defines the location in the directory from which the LDAP search begins
.Parameter SizeLimit
Maximum of results shown for a query
.Parameter SearchScope
A search scope defines how deep to search within the search base.
Base , or zero level, indicates a search of the base object only.
One level indicates a search of objects immediately subordinate to the base object, but does not include the base object itself.
Subtree indicates a search of the base object and the entire subtree of which the base object distinguished name is the topmost object.
.Outputs
System.DirectoryServices.DirectoryEntry
.Example
Get-Computer -Name WRK* -Enabled
-----------
Description
Gets all domain enabled computers which names start with WRK
.Example
Get-Computer -SearchRoot 'CN=Computers,DC=Domain,DC=com' -Disabled
-----------
Description
Gets all disabled computers from the Computers container
.Example
Get-Computer -Name "mpcc1d2c" -SearchRoot "domain.com"
-----------
Description
Gets specific computer in a different domain
.Example
"mpcc1d2c" | Get-Computer -SearchRoot "domain.com"
-----------
Description
Gets computer from Pipe
.Link
http://oliver.lipkau.net/blog/category/powershell/admanagement/
#>

[CmdletBinding(DefaultParametersetName="cn")]
param(
[ValidateNotNullOrEmpty()]
[Parameter(ValueFromPipeline = $true,Mandatory=$true,ParameterSetName='cn',Position=0)]
[Alias("CN")]
[string[]]$Name = "*",

[Parameter(ValueFromPipeline = $true,Mandatory=$true,ParameterSetName='managed',Position=0)]
[ADSI[]]$ManagedBy,

[string]$SearchRoot,

[ValidateNotNullOrEmpty()]
[int]$PageSize = 1000,

[ValidateNotNullOrEmpty()]
[int]$SizeLimit = 0,

[ValidateNotNullOrEmpty()]
[ValidateSet("Base","OneLevel","Subtree")]
[string]$SearchScope = "SubTree",

[switch]$Enabled,

[switch]$Disabled
)

Begin
{
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"
$c = 0

$disableStr = "userAccountControl:1.2.840.113556.1.4.803:=2"
$Enabledf = "(!$disableStr)"
$Disabledf = "($disableStr)"

$root= New-Object System.DirectoryServices.DirectoryEntry("LDAP://RootDSE")
$searcher = New-Object System.DirectoryServices.DirectorySearcher
}

Process
{
switch ($PsCmdlet.ParameterSetName) {
"managed" { $SearchObjects = $ManagedBy.distinguishedName; break}
Default {$SearchObjects = $name; break}
}
foreach ($n in $SearchObjects)
{
Write-Verbose "$($MyInvocation.MyCommand.Name):: Searching for $n"

if(($Enabled) -and (!($Disabled)))
{$EnabledDisabledf = $Enabledf}
elseif(($Disabled) -and (!($Enabled)))
{$EnabledDisabledf = $Disabledf}
else
{$EnabledDisabledf = ""}

switch ($PsCmdlet.ParameterSetName) {
"managed" { $resolve = "(managedBy=$n)"; break}
Default {$resolve = "(|(sAMAccountName=$n)(cn=$n)(displayName=$n)(dNSHostName=$n)(name=$n))"; break}
}


$filter = "(&(objectCategory=Computer)(objectClass=User)$EnabledDisabledf$resolve)"

if (!($SearchRoot))
{$SearchRoot=$root.defaultNamingContext}
elseif (!($SearchRoot) -or ![ADSI]::Exists("LDAP://$SearchRoot"))
{Write-Error "$($MyInvocation.MyCommand.Name):: '$SearchRoot' does not exist";return}
$searcher.SearchRoot = "LDAP://$SearchRoot"
Write-Verbose "$($MyInvocation.MyCommand.Name):: Searching in: $($searcher.SearchRoot)"

$searcher.SearchScope = $SearchScope
$searcher.SizeLimit = $SizeLimit
$searcher.PageSize = $PageSize
$searcher.filter = $filter
Write-Verbose "$($MyInvocation.MyCommand.Name):: Searching for: $($searcher.filter)"
try
{
$searcher.FindAll() | `
Foreach-Object `
{
$c++
Write-Verbose "$($MyInvocation.MyCommand.Name):: Found: $($_.Properties.cn)"
$_.GetDirectoryEntry()
}
}
catch
{
{return $false}
}
}
}

End
{
Write-Verbose "$($MyInvocation.MyCommand.Name):: Results found: $c"
Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"
}
}
Binary file added Functions/Get-Domain.ps1
Binary file not shown.
Binary file added Functions/Get-DomainControllerInfo.ps1
Binary file not shown.
Binary file added Functions/Get-DomainControllers.ps1
Binary file not shown.
Binary file added Functions/Get-DomainPasswordPolicy.ps1
Binary file not shown.
Binary file added Functions/Get-DomainRoot.ps1
Binary file not shown.
Binary file added Functions/Get-EmptyGroup.ps1
Binary file not shown.
Binary file added Functions/Get-FSMORoleHolder.ps1
Binary file not shown.
Binary file added Functions/Get-Forest.ps1
Binary file not shown.
Binary file added Functions/Get-Group.ps1
Binary file not shown.
Binary file added Functions/Get-GroupMember.ps1
Binary file not shown.
Binary file added Functions/Get-GroupMembership.ps1
Binary file not shown.
Binary file added Functions/Get-IPSite.ps1
Binary file not shown.
Binary file added Functions/Get-NearestDC.ps1
Binary file not shown.
Binary file added Functions/Get-Object.ps1
Binary file not shown.
Binary file added Functions/Get-ObjectBySID.ps1
Binary file not shown.
Binary file added Functions/Get-ObjectSID.ps1
Binary file not shown.
Binary file added Functions/Get-RODC.ps1
Binary file not shown.
Binary file added Functions/Get-StaleComputer.ps1
Binary file not shown.
Binary file added Functions/Get-User.ps1
Binary file not shown.
Binary file added Functions/Impersonation.ps1
Binary file not shown.
Binary file added Functions/Move-Object.ps1
Binary file not shown.
Binary file added Functions/New-Computer.ps1
Binary file not shown.
Binary file added Functions/New-Group.ps1
Binary file not shown.
Binary file added Functions/New-OU.ps1
Binary file not shown.
Binary file added Functions/New-Password.ps1
Binary file not shown.
Binary file added Functions/New-User.ps1
Binary file not shown.
Binary file added Functions/Remove-GroupMember.ps1
Binary file not shown.
Binary file added Functions/Remove-Object.ps1
Binary file not shown.
Binary file added Functions/Rename-Object.ps1
Binary file not shown.
Binary file added Functions/Set-ADACL.ps1
Binary file not shown.
Binary file added Functions/Set-Computer.ps1
Binary file not shown.
Binary file added Functions/Set-DomainMode.ps1
Binary file not shown.
Binary file added Functions/Set-ForestMode.ps1
Binary file not shown.
Binary file added Functions/Set-OU.ps1
Binary file not shown.
Binary file added Functions/Set-User.ps1
Binary file not shown.
Binary file added Functions/Test-IsRODC.ps1
Binary file not shown.
Binary file added Functions/Test-SameSubnet.ps1
Binary file not shown.
Binary file added PsADManagement.psd1
Binary file not shown.
Binary file added PsADManagement.psm1
Binary file not shown.

0 comments on commit 7246404

Please sign in to comment.