Skip to content

Commit 113da81

Browse files
committedAug 20, 2016
Added new functions
1 parent a78ffcc commit 113da81

File tree

3 files changed

+75
-31
lines changed

3 files changed

+75
-31
lines changed
 

‎ActiveDirectory/Get-Empty-Groups.ps1

-31
This file was deleted.

‎ActiveDirectory/Get-EmptyGroup.ps1

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#Requires -Version 4 -Module ActiveDirectory
2+
3+
function Get-EmptyGroup
4+
{
5+
<#
6+
.SYNOPSIS
7+
This function queries the Active Directory domain the initiaing computer is in for all groups that have no members.
8+
This is common when attempting to find groups that can be removed.
9+
10+
This does not include default AD groups like Domain Computers, Domain Users, etc.
11+
12+
.EXAMPLE
13+
PS> Get-EmptyGroup
14+
15+
16+
#>
17+
[OutputType([pscustomobject])]
18+
[CmdletBinding()]
19+
param ()
20+
begin
21+
{
22+
$ErrorActionPreference = 'Stop'
23+
}
24+
process
25+
{
26+
try
27+
{
28+
@(Get-ADGroup -Filter * -Properties isCriticalSystemObject,Members).where({ (-not $_.isCriticalSystemObject) -and ($_.Members.Count -eq 0) })
29+
}
30+
catch
31+
{
32+
$PSCmdlet.ThrowTerminatingError($_)
33+
}
34+
}
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Get-FunctionDefaultParameter
2+
{
3+
<#
4+
.SYNOPSIS
5+
This is a function that will find all of the default parameter names and values from a given function.
6+
7+
.EXAMPLE
8+
PS> Get-FunctionDefaultParameter -FunctionName Get-Something
9+
10+
.PARAMETER FuntionName
11+
A mandatory string parameter representing the name of the function to find default parameters to.
12+
13+
#>
14+
[CmdletBinding()]
15+
[OutputType([hashtable])]
16+
param
17+
(
18+
[Parameter(Mandatory)]
19+
[ValidateNotNullOrEmpty()]
20+
[string]$FunctionName
21+
)
22+
try
23+
{
24+
$ast = (Get-Command $FunctionName).ScriptBlock.Ast
25+
26+
$select = @{ n = 'Name'; e = { $_.Name.VariablePath.UserPath } },
27+
@{ n = 'Value'; e = { $_.DefaultValue.Extent.Text -replace "`"|'" } }
28+
29+
$ht = @{}
30+
@($ast.FindAll({ $args[0] -is [System.Management.Automation.Language.ParameterAst] }, $true) | Where-Object { $_.DefaultValue } | Select-Object $select).foreach({
31+
$ht[$_.Name] = $_.Value
32+
})
33+
$ht
34+
35+
}
36+
catch
37+
{
38+
Write-Error -Message $_.Exception.Message
39+
}
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.