Open-UserHomeDrive.ps1:

param(
$userName = $Env:USERNAME
)

$dsam = "System.DirectoryServices.AccountManagement"
$rtn = [reflection.assembly]::LoadWithPartialName($dsam)
$cType = "domain"
$iType = "SamAccountName"
$UserDomain=$env:userDomain
$dsamUserPrincipal = [type]"$dsam.userPrincipal"
$cContainer=[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().GetDirectoryEntry().Distinguishedname

$ctx = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($cType,$UserDomain,$cContainer)
$user = $dsamUserPrincipal::FindByIdentity($ctx,$iType,$userName)

[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null

if($user.HomeDrive -eq $null)
{
$str = "No HomeDrive for user $userName"
[System.Windows.Forms.MessageBox]::Show($str)
}
else
{
explorer $User.HomeDirectory
}

And add this to UsersRemoteSoftwares.xml

<Software>
<ProgramPath>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</ProgramPath>
<Options>-ExecutionPolicy Bypass -file "D:\DATA\Philips\PowershellScript\Open-UserHomeDrive.ps1" -userName {comboboxUserName}</Options>
<Name>Home Drive</Name>
</Software>

User-Unlock.ps1:

param(
$userName =$env:username
)

$dsam = "System.DirectoryServices.AccountManagement"
$rtn = [reflection.assembly]::LoadWithPartialName($dsam)
$cType = "domain"
$iType = "SamAccountName"
$UserDomain=$env:userDomain
$dsamUserPrincipal = "$dsam.userPrincipal" -as [type]
$cContainer=[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().GetDirectoryEntry().Distinguishedname

$ctx = New-Object System.DirectoryServices.AccountManagement.PrincipalContext($cType,$UserDomain,$cContainer)
$user = $dsamUserPrincipal::FindByIdentity($ctx,$iType,$userName)
$User.UnlockAccount()

And add this to UsersRemoteSoftwares.xml

<Software>
<ProgramPath>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</ProgramPath>
<Options>-ExecutionPolicy Bypass -file "D:\DATA\Philips\PowershellScript\User-Unlock.ps1" -userName {comboboxUserName}</Options>
<Name>Unlock</Name>
</Software>

Last edited Apr 21, 2015 at 10:38 AM by itamartz, version 7