I need to extract client_TargetText
and AnotherTargetText_110953_140521
from the results I get when running the whoami /groups
command:
Powershell Results:
Group Name Type SID Attributes
========================================== ================ ============================================= ==================================================
Everyone Well-known group S-1-1-0 Mandatory group, Enabled by default, Enabled group
BUILTIN\Users Alias S-1-5-32-545 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\INTERACTIVE Well-known group S-1-5-4 Mandatory group, Enabled by default, Enabled group
CONSOLE LOGON Well-known group S-1-2-1 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\Authenticated Users Well-known group S-1-5-11 Mandatory group, Enabled by default, Enabled group
NT AUTHORITY\This Organization Well-known group S-1-5-15 Mandatory group, Enabled by default, Enabled group
LOCAL Well-known group S-1-2-0 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\GGM-FIRE-PC Group S-1-5-21-457414007-2867176591-488352320-6061 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\myles_gp Group S-1-5-21-457414007-2867176591-488352320-12531 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\GGM-RDP Group S-1-5-21-457414007-2867176591-488352320-13873 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\client_TargetText Group S-1-5-21-457414007-2867176591-488352320-7924 Mandatory group, Enabled by default, Enabled group
MYDOMAIN\AnotherTargetText_110953_140521 Group S-1-5-21-457414007-2867176591-488352320-13947 Mandatory group, Enabled by default, Enabled group
Authentication authority asserted identity Well-known group S-1-18-1 Mandatory group, Enabled by default, Enabled group
Mandatory Label\Medium Mandatory Level Label S-1-16-8192
PS C:\Users\test.dev>
How would I go about grabbing client_TargetText
and removing the client_
so it becomes just TargetText
and then make this $Param1
in the script below?
(client_
is always present in the text I need to grab for $Param1)
Then how would I go about grabbing AnotherTargetText_110953_140521
so it can be made into $Param2
in the script below?
(The desired text for $Param2
is always suffixed by 6digits_6digits
in these AD groups)
My goal is to somehow send this text over into a script I use for creating server shortcuts on user desktops.
The results will be different for each user when whoami
runs so I think the only wildcards that can be used are client_
and 6digits_6digits
. Any helping me towards finding this answer very much appreciated as I am trying to learn how this would work but can't figure it out.
The script below is the desired outcome after successfully parsing those two pieces of text over and turning them into $Param1
and $Param2
:
function set-shortcut {
param ( [string]$SourceLnk, [string]$DestinationPath )
$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($SourceLnk)
$Shortcut.TargetPath = $DestinationPath
$Shortcut.Save()
}
try{
$Param1 = TargetText
$Param2 = AnotherTargetText_110953_140521
$SourcePath = \\server\data\designs\$Param1\$Param2\data_store"
set-shortcut "%USERPROFILE%\Desktop\data_store.lnk" "$SourcePath"
"This worked"
pause
}
catch
{
"This didn't work"
}
pause
Get-LocalUser
cmdlet. it lists the groups the account is a member of. then you can filter for your pattern in the.Name
property. once you have the group name as text, just do a-replace
OR a.Split()
as you prefer.