forked from RamblingCookieMonster/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04dbb03
commit 860885d
Showing
16 changed files
with
2,915 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
function ConvertFrom-SID { | ||
<# | ||
.SYNOPSIS | ||
Convert SID to user or computer account name | ||
.DESCRIPTION | ||
Convert SID to user or computer account name | ||
.PARAMETER SID | ||
One or more SIDs to convert | ||
.EXAMPLE | ||
ConvertFrom-SID S-1-5-21-2139171146-395215898-1246945465-2359 | ||
.EXAMPLE | ||
'S-1-5-32-580' | ConverFrom-SID | ||
.FUNCTIONALITY | ||
Active Directory | ||
.NOTES | ||
SID conversion for well known SIDs from http://support.microsoft.com/kb/243330 | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory=$true,ValueFromPipeline=$true)] | ||
[string[]]$sid | ||
) | ||
|
||
Begin{ | ||
#well known SID to name map | ||
$wellKnownSIDs = @{ | ||
'S-1-0' = 'Null Authority' | ||
'S-1-0-0' = 'Nobody' | ||
'S-1-1' = 'World Authority' | ||
'S-1-1-0' = 'Everyone' | ||
'S-1-2' = 'Local Authority' | ||
'S-1-2-0' = 'Local' | ||
'S-1-2-1' = 'Console Logon' | ||
'S-1-3' = 'Creator Authority' | ||
'S-1-3-0' = 'Creator Owner' | ||
'S-1-3-1' = 'Creator Group' | ||
'S-1-3-2' = 'Creator Owner Server' | ||
'S-1-3-3' = 'Creator Group Server' | ||
'S-1-3-4' = 'Owner Rights' | ||
'S-1-5-80-0' = 'All Services' | ||
'S-1-4' = 'Non-unique Authority' | ||
'S-1-5' = 'NT Authority' | ||
'S-1-5-1' = 'Dialup' | ||
'S-1-5-2' = 'Network' | ||
'S-1-5-3' = 'Batch' | ||
'S-1-5-4' = 'Interactive' | ||
'S-1-5-6' = 'Service' | ||
'S-1-5-7' = 'Anonymous' | ||
'S-1-5-8' = 'Proxy' | ||
'S-1-5-9' = 'Enterprise Domain Controllers' | ||
'S-1-5-10' = 'Principal Self' | ||
'S-1-5-11' = 'Authenticated Users' | ||
'S-1-5-12' = 'Restricted Code' | ||
'S-1-5-13' = 'Terminal Server Users' | ||
'S-1-5-14' = 'Remote Interactive Logon' | ||
'S-1-5-15' = 'This Organization' | ||
'S-1-5-17' = 'This Organization' | ||
'S-1-5-18' = 'Local System' | ||
'S-1-5-19' = 'NT Authority' | ||
'S-1-5-20' = 'NT Authority' | ||
'S-1-5-32-544' = 'Administrators' | ||
'S-1-5-32-545' = 'Users' | ||
'S-1-5-32-546' = 'Guests' | ||
'S-1-5-32-547' = 'Power Users' | ||
'S-1-5-32-548' = 'Account Operators' | ||
'S-1-5-32-549' = 'Server Operators' | ||
'S-1-5-32-550' = 'Print Operators' | ||
'S-1-5-32-551' = 'Backup Operators' | ||
'S-1-5-32-552' = 'Replicators' | ||
'S-1-5-64-10' = 'NTLM Authentication' | ||
'S-1-5-64-14' = 'SChannel Authentication' | ||
'S-1-5-64-21' = 'Digest Authority' | ||
'S-1-5-80' = 'NT Service' | ||
'S-1-5-83-0' = 'NT VIRTUAL MACHINE\Virtual Machines' | ||
'S-1-16-0' = 'Untrusted Mandatory Level' | ||
'S-1-16-4096' = 'Low Mandatory Level' | ||
'S-1-16-8192' = 'Medium Mandatory Level' | ||
'S-1-16-8448' = 'Medium Plus Mandatory Level' | ||
'S-1-16-12288' = 'High Mandatory Level' | ||
'S-1-16-16384' = 'System Mandatory Level' | ||
'S-1-16-20480' = 'Protected Process Mandatory Level' | ||
'S-1-16-28672' = 'Secure Process Mandatory Level' | ||
'S-1-5-32-554' = 'BUILTIN\Pre-Windows 2000 Compatible Access' | ||
'S-1-5-32-555' = 'BUILTIN\Remote Desktop Users' | ||
'S-1-5-32-556' = 'BUILTIN\Network Configuration Operators' | ||
'S-1-5-32-557' = 'BUILTIN\Incoming Forest Trust Builders' | ||
'S-1-5-32-558' = 'BUILTIN\Performance Monitor Users' | ||
'S-1-5-32-559' = 'BUILTIN\Performance Log Users' | ||
'S-1-5-32-560' = 'BUILTIN\Windows Authorization Access Group' | ||
'S-1-5-32-561' = 'BUILTIN\Terminal Server License Servers' | ||
'S-1-5-32-562' = 'BUILTIN\Distributed COM Users' | ||
'S-1-5-32-569' = 'BUILTIN\Cryptographic Operators' | ||
'S-1-5-32-573' = 'BUILTIN\Event Log Readers' | ||
'S-1-5-32-574' = 'BUILTIN\Certificate Service DCOM Access' | ||
'S-1-5-32-575' = 'BUILTIN\RDS Remote Access Servers' | ||
'S-1-5-32-576' = 'BUILTIN\RDS Endpoint Servers' | ||
'S-1-5-32-577' = 'BUILTIN\RDS Management Servers' | ||
'S-1-5-32-578' = 'BUILTIN\Hyper-V Administrators' | ||
'S-1-5-32-579' = 'BUILTIN\Access Control Assistance Operators' | ||
'S-1-5-32-580' = 'BUILTIN\Remote Management Users' | ||
} | ||
} | ||
|
||
Process { | ||
|
||
#loop through provided SIDs | ||
foreach($id in $sid){ | ||
|
||
#Map name to well known sid. If this fails, use .net to get the account | ||
if($name = $wellKnownSIDs[$id]){ } | ||
else{ | ||
|
||
#Try to translate the SID to an account | ||
Try{ | ||
$objSID = New-Object System.Security.Principal.SecurityIdentifier($id) | ||
$name = ( $objSID.Translate([System.Security.Principal.NTAccount]) ).Value | ||
} | ||
Catch{ | ||
$name = "Not a valid SID or could not be identified" | ||
Write-Verbose "$id is not a valid SID or could not be identified" | ||
} | ||
} | ||
|
||
#Display the results | ||
New-Object -TypeName PSObject -Property @{ | ||
SID = $id | ||
Name = $name | ||
} | Select SID, Name | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
function Get-ADGroupMembers { | ||
<# | ||
.SYNOPSIS | ||
Return all group members for specified groups. | ||
.FUNCTIONALITY | ||
Active Directory | ||
.DESCRIPTION | ||
Return all group members for specified groups. Requires .NET 3.5, does not require RSAT | ||
.PARAMETER Group | ||
One or more Security Groups to enumerate | ||
.PARAMETER Recurse | ||
Whether to recurse groups. Note that subgroups are NOT returned if this is true, only user accounts | ||
Default value is $True | ||
.EXAMPLE | ||
#Get all group members in Domain Admins or nested subgroups, only include samaccountname property | ||
Get-ADGroupMembers "Domain Admins" | Select-Object -ExpandProperty samaccountname | ||
.EXAMPLE | ||
#Get members for objects returned by Get-ADGroupMembers | ||
Get-ADGroupMembers -group "Domain Admins" | Get-Member | ||
#> | ||
[cmdletbinding()] | ||
Param( | ||
[Parameter(Position=0, ValueFromPipeline=$true)] | ||
[string[]]$group = 'Domain Admins', | ||
|
||
[bool]$Recurse = $true | ||
) | ||
|
||
Begin { | ||
#Add the .net type | ||
$type = 'System.DirectoryServices.AccountManagement' | ||
Try{ | ||
Add-Type -AssemblyName $type -ErrorAction Stop | ||
} | ||
Catch { | ||
Throw "Could not load $type`: Confirm .NET 3.5 or later is installed" | ||
Break | ||
} | ||
|
||
#set up context type | ||
# use the 'Machine' ContextType if you want to retrieve local group members | ||
# http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.contexttype.aspx | ||
$ct = [System.DirectoryServices.AccountManagement.ContextType]::Domain | ||
} | ||
|
||
Process { | ||
#List group members | ||
foreach($GroupName in $group){ | ||
Try { | ||
$grp = [System.DirectoryServices.AccountManagement.GroupPrincipal]::FindByIdentity($ct,$GroupName) | ||
|
||
#display results or warn if no results | ||
if($grp){ | ||
$grp.GetMembers($Recurse) | ||
} | ||
else{ | ||
Write-Warning "Could not find group '$GroupName'" | ||
} | ||
} | ||
Catch { | ||
Write-Error "Could not obtain members for $GroupName`: $_" | ||
Continue | ||
} | ||
} | ||
} | ||
End{ | ||
#cleanup | ||
$ct = $grp = $null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
function Get-FolderEntry { | ||
<# | ||
.SYNOPSIS | ||
Lists all folders under a specified folder regardless of character limitation on path depth. | ||
.DESCRIPTION | ||
Lists all folders under a specified folder regardless of character limitation on path depth. | ||
This is based on Boe's Get-FolderItem command here: http://gallery.technet.microsoft.com/scriptcenter/Get-Deeply-Nested-Files-a2148fd7 | ||
.FUNCTIONALITY | ||
Computers | ||
.PARAMETER Path | ||
One or more paths to search for subdirectories under | ||
.PARAMETER ExcludeFolder | ||
One or more paths to exclude from query | ||
.EXAMPLE | ||
Get-FolderEntry -Path "C:\users" | ||
FullPathLength FullName FileCount | ||
-------------- -------- --------- | ||
9 C:\Users\ 1 | ||
23 C:\Users\SomeUser\ 7 | ||
31 C:\Users\SomeUser\AppData\ 0 | ||
37 C:\Users\SomeUser\AppData\Local\ 0 | ||
47 C:\Users\SomeUser\AppData\Local\Microsoft\ 0 | ||
... | ||
Description | ||
----------- | ||
Returns all folders under the users folder. | ||
.EXAMPLE | ||
Get-FolderEntry -Path "C:\users" -excludefolder "C:\Users\SomeUser\AppData\Local\Microsoft\" | ||
FullPathLength FullName FileCount | ||
-------------- -------- --------- | ||
9 C:\Users\ 1 | ||
23 C:\Users\SomeUser\ 7 | ||
31 C:\Users\SomeUser\AppData\ 0 | ||
37 C:\Users\SomeUser\AppData\Local\ 0 | ||
52 C:\Users\SomeUser\AppData\Local\Microsoft Help\ 0 #NOTE that we skipped the excludefolder path | ||
... | ||
Description | ||
----------- | ||
Returns all folders under the users folder, excluding C:\Users\SomeUser\AppData\Local\Microsoft\ and all subdirectories | ||
.INPUTS | ||
System.String | ||
.OUTPUTS | ||
System.IO.RobocopyDirectoryInfo | ||
.NOTES | ||
Name: Get-FolderItem | ||
Author: Boe Prox | ||
Date Created: 31 March 2013 | ||
Updated by rcm | ||
#> | ||
[cmdletbinding(DefaultParameterSetName='Filter')] | ||
Param ( | ||
[parameter( | ||
Position=0, | ||
ValueFromPipeline=$True, | ||
ValueFromPipelineByPropertyName=$True)] | ||
[Alias('FullName')] | ||
[string[]]$Path = $PWD, | ||
|
||
[parameter(ParameterSetName='Filter')] | ||
[string[]]$Filter = '*.*', | ||
|
||
[parameter(ParameterSetName='Exclude')] | ||
[string[]]$ExcludeFolder | ||
) | ||
|
||
Begin { | ||
|
||
#Define arguments for robocopy and regex to parse results | ||
$array = @("/L","/S","/NJH","/BYTES","/FP","/NC","/NFL","/TS","/XJ","/R:0","/W:0") | ||
$regex = "^(?<Count>\d+)\s+(?<FullName>.*)" | ||
|
||
#Create an arraylist | ||
$params = New-Object System.Collections.Arraylist | ||
$params.AddRange($array) | ||
} | ||
|
||
Process { | ||
|
||
ForEach ($item in $Path) { | ||
Try { | ||
|
||
$item = (Resolve-Path -LiteralPath $item -ErrorAction Stop).ProviderPath | ||
|
||
If (-Not (Test-Path -LiteralPath $item -Type Container -ErrorAction Stop)) { | ||
Write-Warning ("{0} is not a directory and will be skipped" -f $item) | ||
Return | ||
} | ||
|
||
If ($PSBoundParameters['ExcludeFolder']) { | ||
$filterString = ($ExcludeFolder | %{"'$_'"}) -join ',' | ||
$Script = "robocopy `"$item`" NULL $Filter $params /XD $filterString" | ||
} | ||
Else { | ||
$Script = "robocopy `"$item`" NULL $Filter $params" | ||
} | ||
|
||
Write-Verbose ("Scanning {0}" -f $item) | ||
|
||
#Run robocopy and parse results into an object. | ||
Invoke-Expression $Script | ForEach { | ||
Try { | ||
If ($_.Trim() -match $regex) { | ||
$object = New-Object PSObject -Property @{ | ||
FullName = $matches.FullName | ||
FileCount = [int64]$matches.Count | ||
FullPathLength = [int] $matches.FullName.Length | ||
} | select FullName, FileCount, FullPathLength | ||
$object.pstypenames.insert(0,'System.IO.RobocopyDirectoryInfo') | ||
Write-Output $object | ||
} Else { | ||
Write-Verbose ("Not matched: {0}" -f $_) | ||
} | ||
} Catch { | ||
Write-Warning ("{0}" -f $_.Exception.Message) | ||
Return | ||
} | ||
} | ||
} Catch { | ||
Write-Warning ("{0}" -f $_.Exception.Message) | ||
Return | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.