Creation of links

The main reason of doing this is creation of links during computer configuration for end user. It is very boring to do it manually :).

Functions for get and creating code:

function Get-Shortcut {
param(
$path = $null
)

$obj = New-Object -ComObject WScript.Shell

if ($path -eq $null) {
$pathUser = [System.Environment]::GetFolderPath('StartMenu')
$pathCommon = $obj.SpecialFolders.Item('AllUsersStartMenu')
$path = dir $pathUser, $pathCommon -Filter *.lnk -Recurse 
}
if ($path -is [string]) {
$path = dir $path -Filter *.lnk
}
$path | ForEach-Object { 
if ($_ -is [string]) {
$_ = dir $_ -Filter *.lnk
}
if ($_) {
$link = $obj.CreateShortcut($_.FullName)

$info = @{}
$info.Hotkey = $link.Hotkey
$info.TargetPath = $link.TargetPath
$info.LinkPath = $link.FullName
$info.Arguments = $link.Arguments
$info.Target = try {Split-Path $info.TargetPath -Leaf } catch { 'n/a'}
$info.Link = try { Split-Path $info.LinkPath -Leaf } catch { 'n/a'}
$info.WindowStyle = $link.WindowStyle
$info.IconLocation = $link.IconLocation

New-Object PSObject -Property $info
}
}
}

function Set-Shortcut {
param(
[Parameter(ValueFromPipelineByPropertyName=$true)]
$LinkPath,
$Hotkey,
$IconLocation,
$Arguments,
$TargetPath
)
begin {
$shell = New-Object -ComObject WScript.Shell
}

process {
$link = $shell.CreateShortcut($LinkPath)

$PSCmdlet.MyInvocation.BoundParameters.GetEnumerator() |
Where-Object { $_.key -ne 'LinkPath' } |
ForEach-Object { $link.$($_.key) = $_.value }
$link.Save()
}
}

 

Command for creation of icon Google Chat (replace %username% with real username also ensure that data for the specific application exists… in this case application of Google Chat located in folder _crx_mdpkiolbdkhdjpekfbkbmhigcaggjagi ).

Set-Shortcut -LinkPath "C:\Users\%username%\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Google Chat.lnk" -TargetPath "C:\Program Files (x86)\Google\Chrome\Application\chrome_proxy.exe" -IconLocation "C:\Users\%username%\AppData\Local\Google\Chrome\User Data\Default\Web Applications\_crx_mdpkiolbdkhdjpekfbkbmhigcaggjagi\Google Chat.ico,0" -Arguments "--profile-directory=Default --app-id=mdpkiolbdkhdjpekfbkbmhigcaggjagi"

 

Note that functions are not mine… originally are from:

https://stackoverflow.com/questions/484560/editing-shortcut-lnk-properties-with-powershell

Pretty usefull to scrample part of strong password with MD5. Attacker who is trying dictionary attack on password combined with weak password and MD5 has of other weak password has dificult times 🙂 .

 


░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░┌────────────┬──────────────┐░░░░░░░░
░░░│░░░░░░░░░░░░│░░░░░░░░░░░░░░│░░░░░░░░
░░░│ Weak pwd1  │ MD5 of pwd2  │░░░░░░░░
░░░└────────────┴───────┬──────┘░░░░░░░░
░░░░░░░░│░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░│░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░│░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░│░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░│░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░Weak pwd1░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░┌───────────┴────────┐░░░░░░
░░░░░░░░░░░░│░░░░░░░░░░░░░░░░░░░░│░░░░░░
░░░░░░░░░░░░│ MD5 hasher         │░░░░░░
░░░░░░░░░░░░└───────────┬────────┘░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░│░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░Weak pwd2 ░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░

 

Add-Type -AssemblyName Microsoft.VisualBasic
$someString = [Microsoft.VisualBasic.Interaction]::InputBox("Enter string to be hashed ", "String2MD5 convertor", "String")

$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$utf8 = New-Object -TypeName System.Text.UTF8Encoding
$hash = [System.BitConverter]::ToString($md5.ComputeHash($utf8.GetBytes($someString)))
$hash.Replace("-","").tolower()
Set-Clipboard -Value $hash.Replace("-","").tolower()

First create scheduled task with no password credentical configured. Let’s suppose task name is „TaskName“ and GMSA account which we want to use is already configured on scheduler server . Account name in AD is  „GmsaAccount“.

 

$task = Get-ScheduledTask | ?{$_.TaskName -eq "TaskName"}

$task = Set-ScheduledTask -User GmsaAccount$

$task = Get-ScheduledTask | ?{$_.TaskName -eq "TaskName"}

$task.Principal.LogonType = "Password"

Set-ScheduledTask $task

 

Powershell array management

Example of array management  where $Record object can be defined at time of initialization or can be blank (# section).

 

$OutputArray = @()

#/in loop

$Record = @{
"attr1" = "Value1"
"attr2" = "Value2"
"attr3" = "Value3"
}

#$Record =@{}

$Record."attr4" = "Value4"

$objrecord = New-Object PSObject -property $Record
$OutputArray += $objrecord

#/in loop

$OutputArray | out-gridview

 

 

AD investigation

Here is quick cheatsheet to review configuration of Active Directory.

 

Hostname


Net config rdr


 Netdom query fsmo


Nltest /dclist:


Nltest /domain_trusts


Nltest /dnsgetdc:domain.com

(replace domain.com with actual domain name)

 

Sometimes Get-ADGroupMembers -recursive is not enough. This is workaround…

 

Function Get-ADGroupMemberRecursive($groupname)
{
$list = Get-ADGroupMember $groupname
$recurse = $list | ?{$_.ObjectClass -eq "group"}
foreach($recursegroup in $recurse){
$out = Get-ADGroupMemberRecursive $recursegroup.samaccountname
$list=$list + $out
}

$hash = @{}

foreach($record in $list){
if ($hash.Contains($record.objectguid)){}
else {
$hash.add($record.objecguid,$record)
}
}

Return ($hash.Values | ?{$_.objectclass -ne "group"})
}

 

 

Creation of hashtable

$hashatble = @{}

 

 

Adding value

$hashtable.add($key,$value)

 

 

Loading hastable if input might have duplicate keys

foreach($item in $itemlist)
{
  if ($hashtable.Contains($item.key))
   {
   #noting
   }
else
   {
   $hashtable.add($item.key,$item.value)
   }
}

 

List filtering based on hastable

#object is not in hastable list

$listobjectsarenotinhashtable = $objectlist | ?{$hashtable.($_) -eq $null

#object is  in hastable list

$listobjectsarenotinhashtable = $objectlist | ?{$hashtable.($_) -ne $null

 

Another smooth gameplay of CoD

Game works great with XIM 4 as it is supported game. There is no reason to do some hardcore adjustmet, just set full sensitivity in game and adjust sensitivity in XIM menu ask you preffer. My settings is default just sentivity raised from 18 to 25 but it is just my prefference. 

Call of Duty is traditionally nice handeled and WW2 is not exception. Don’t think that it is quile to PC gaming but you can enjoy game without serious issues.

Problems

Only problem i have are sequences when special action is required (mostly action like moving left stick  to some position and press sqare button) is little bit iritating since you must aim to this location with WASD and usually i don’t achieve it in limited time so situation repeats. This is however not related directly to XIM it is rather the way how developers tried to create cinematic scenes more interactive.

To fix anoying moving of cursor using WASD buttons i have added to middle-mouse button alternativ controll (in screenshots it is named as action) which during middle mouse hold set lift stick to mouse movement to achieve better aiming to objective in cinematic scenes.

Feeling

I would higly recommend it for XIM 4. Gameplay is awesome.

Aiming

Aiming is not the problem at all.

Turning

Turning is little mit slower but not a big deal. You can handle it without problem after five minutes of gameplay. If i compare it to other CoD it is not worse or better.

XIM Config

Video Gameplay

Rating:

Aiming Turning Jitter Overloading Total
9/10 9/10 8/10 9/10 9/10

Config Code