Create Invoke-DACheck.ps1

This commit is contained in:
Alexander Rymdeko-Harvey
2016-01-07 15:01:50 -05:00
parent 375813c1b5
commit e483c4977a
+72
View File
@@ -0,0 +1,72 @@
function Invoke-DACheck {
<#
.SYNOPSIS
Checks to see if current user is in DA Groups and if he is returns a specfic string alerting user that they are DA for Automated purposes.
#>
process {
$User = Get-User
$DomainAdmins = Get-DomainAdmins
foreach($DomainUser in $DomainAdmins)
{
if($User -eq $DomainUser)
{
Write-Host "Found-DA-User: $User"
}
}
}
}
function Get-DomainAdmins {
<#
.SYNOPSIS
Montiotrs the current DA accounts and alerts the desired admin if a change where to take place whithin the group.
.PARAMETER CheckRate
Pass me a command in a Variable.
.PARAMETER EmailAdress
Pass me a command in a Variable.
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline=$True)]
[string]$Command
)
process
{
$Ver = $PSVersionTable.PSVersion
If ($Ver.Major -eq 4)
{
$DAobj = Get-ADGroupMember -Identity Domain Admins
return $DAobj.name
}
Else
{
$Recurse = $true
Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain
$group=[System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($ct,'Domain Admins')
$Obj = $group.GetMembers($Recurse) | select SamAccountName
$DAUsers = foreach($x in $group.GetMembers($Recurse)){$x.SamAccountName}
return $DAUsers
}
}
}
function Get-User {
<#
.SYNOPSIS
Montiotrs the current DA accounts and alerts the desired admin if a change where to take place whithin the group.
#>
process {
$User = [Security.Principal.WindowsIdentity]::GetCurrent().Name
$User = $User.trimstart([Environment]::UserDomainName)
$User = $User.trimstart("\")
return $User
}
}