Skip to content

Commit bc6b2dd

Browse files
committed
Update InGroup.ps1
1 parent f3ec453 commit bc6b2dd

File tree

1 file changed

+55
-59
lines changed

1 file changed

+55
-59
lines changed

InGroup.ps1

+55-59
Original file line numberDiff line numberDiff line change
@@ -5,72 +5,68 @@ function InGroup {
55
.NOTES
66
Author: Julian West
77
Creative GNU General Public License, version 3 (GPLv3);
8-
________________________________________________
9-
/ \
10-
| _________________________________________ |
11-
| | | |
12-
| | PS C:\ > WRITE-HOST "$ATTRIBUTION" | |
13-
| | | |
14-
| | THIS IS A J-DUB SCRIPT | |
15-
| | | |
16-
| | https://github.com/J-DubAppss | |
17-
| | | |
18-
| | julianwest.me | |
19-
| | @julian_west | |
20-
| | | |
21-
| | | |
22-
| | | |
23-
| | | |
24-
| | | |
25-
| |_________________________________________| |
26-
| |
27-
\_________________________________________________/
28-
\___________________________________/
29-
___________________________________________
30-
_-' .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. --- `-_
31-
_-'.-.-. .---.-.-.-.-.-.-.-.-.-.-.-.-.-.-.--. .-.-.`-_
32-
_-'.-.-.-. .---.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-`__`. .-.-.-.`-_
33-
_-'.-.-.-.-. .-----.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-----. .-.-.-.-.`-_
34-
_-'.-.-.-.-.-. .---.-. .-------------------------. .-.---. .---.-.-.-.`-_
8+
________________________________________________
9+
/ \
10+
| _________________________________________ |
11+
| | | |
12+
| | PS C:\ > WRITE-HOST "$ATTRIBUTION" | |
13+
| | | |
14+
| | THIS IS A J-DUB SCRIPT | |
15+
| | | |
16+
| | https://github.com/J-DubAppss | |
17+
| | | |
18+
| | julianwest.me | |
19+
| | @julian_west | |
20+
| | | |
21+
| | | |
22+
| | | |
23+
| | | |
24+
| | | |
25+
| |_________________________________________| |
26+
| |
27+
\_________________________________________________/
28+
\___________________________________/
29+
___________________________________________
30+
_-' .-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. --- `-_
31+
_-'.-.-. .---.-.-.-.-.-.-.-.-.-.-.-.-.-.-.--. .-.-.`-_
32+
_-'.-.-.-. .---.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-`__`. .-.-.-.`-_
33+
_-'.-.-.-.-. .-----.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-----. .-.-.-.-.`-_
34+
_-'.-.-.-.-.-. .---.-. .-------------------------. .-.---. .---.-.-.-.`-_
3535
:-------------------------------------------------------------------------:
3636
`---._.-------------------------------------------------------------._.---'
3737
.SYNOPSIS
3838
Check if the current user is in a specified group
3939
.DESCRIPTION
4040
Simple Check to see if current user is in a specified group using .NET Framework
41-
Variations of the PS script exists all over Github in various forms and
42-
functions, and this is just my own quick take on it.
41+
Variations of this PS Function exist all over Github in various forms, and this is just my own quick take on it.
4342
.PARAMETER GroupName
4443
The name of the group to check
4544
.EXAMPLE
4645
# Check if the current user is in the Administrators group
4746
$b = InGroup 'Administrators'
4847
#>
49-
Param(
50-
[string]$GroupName
51-
)
52-
53-
if($GroupName)
54-
{
55-
$mytoken = [System.Security.Principal.WindowsIdentity]::GetCurrent()
56-
$me = New-Object System.Security.Principal.WindowsPrincipal($mytoken)
57-
return $me.IsInRole($GroupName)
58-
}
59-
else
60-
{
61-
$user_token = [System.Security.Principal.WindowsIdentity]::GetCurrent()
62-
$groups = New-Object System.Collections.ArrayList
63-
foreach($group in $user_token.Groups)
64-
{
65-
[void] $groups.Add( $group.Translate("System.Security.Principal.NTAccount") )
66-
}
67-
return $groups
68-
}
69-
}
70-
71-
72-
#region LICENSE
73-
<#
48+
Param(
49+
[string]$GroupName
50+
)
51+
52+
if ($GroupName) {
53+
$mytoken = [System.Security.Principal.WindowsIdentity]::GetCurrent()
54+
$me = New-Object System.Security.Principal.WindowsPrincipal($mytoken)
55+
return $me.IsInRole($GroupName)
56+
}
57+
else {
58+
$user_token = [System.Security.Principal.WindowsIdentity]::GetCurrent()
59+
$groups = New-Object System.Collections.ArrayList
60+
foreach ($group in $user_token.Groups) {
61+
[void] $groups.Add( $group.Translate("System.Security.Principal.NTAccount") )
62+
}
63+
return $groups
64+
}
65+
}
66+
67+
68+
#region LICENSE
69+
<#
7470
Creative GNU General Public License, version 3 (GPLv3)
7571
Julian West
7672
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
@@ -79,10 +75,10 @@ function InGroup {
7975
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
8076
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8177
#>
82-
#endregion LICENSE
83-
84-
#region DISCLAIMER
85-
<#
78+
#endregion LICENSE
79+
80+
#region DISCLAIMER
81+
<#
8682
DISCLAIMER:
8783
- Use at your own risk, etc.
8884
- This is open-source software, if you find an issue try to fix it yourself. There is no support and/or warranty in any kind
@@ -92,4 +88,4 @@ function InGroup {
9288
- By using the Software, you agree to the License, Terms, and any Conditions declared and described above
9389
- If you disagree with any of the terms, and any conditions declared: delete it and build your own solution
9490
#>
95-
#endregion DISCLAIMER
91+
#endregion DISCLAIMER

0 commit comments

Comments
 (0)