Skip to content
English
  • There are no suggestions because the search field is empty.

FSLogix und Memtime: PowerShell Script

This PowerShell script can help programs such as Memtime, which have an auto-start function, to work with FSLogix profiles.

What the Script Does

The PowerShell script handles this safely and automatically:

  1. Stops Memtime only in the current user session
    1. Includes domain and user ownership check
    2. Does not affect other users on the same server
  2. Waits until FSLogix reports that the profile for the current SID is attached
  3. Starts Memtime only after the profile is ready
  4. Works reliably in multi-user RDS environments

Save the script as:

# ================================
# Start-Memtime-After-FSLogix.ps1
# (multi-user-sicher, FSLogix-wait)
# ================================

$ErrorActionPreference = "SilentlyContinue"

$memtimeExe = "C:\Program Files\memtime\memtime.exe"
$timeoutSec = 120
$sleepSec   = 2

# Aktuellen Benutzer / SID
$identity  = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$sid       = $identity.User.Value
$domain    = $env:USERDOMAIN
$user      = $env:USERNAME

# --- Memtime nur für diesen User beenden (nicht andere Sessions) ---
Get-CimInstance Win32_Process -Filter "Name='memtime.exe'" |
  ForEach-Object {
    $owner = Invoke-CimMethod -InputObject $_ -MethodName GetOwner
    if ($owner.Domain -eq $domain -and $owner.User -eq $user) {
      Stop-Process -Id $_.ProcessId -Force
    }
  }

function Test-FSLogixProfileReady([string]$sid) {
  $base = "HKLM:\SOFTWARE\FSLogix\Profiles\Sessions"
  if (-not (Test-Path $base)) { return $false }

  foreach ($k in Get-ChildItem $base) {
    $p = Get-ItemProperty $k.PSPath
    if ($p.Sid -eq $sid -and $p.ProfileImagePath -and $p.ProfileImagePath.Length -gt 3) {
      return $true
    }
  }
  return $false
}

# --- Warten bis FSLogix bereit ist (oder Timeout) ---
$deadline = (Get-Date).AddSeconds($timeoutSec)
while ((Get-Date) -lt $deadline) {
  if (Test-FSLogixProfileReady $sid) { break }
  Start-Sleep -Seconds $sleepSec
}

# --- Memtime starten (nur wenn nicht schon läuft) ---
$alreadyRunning = Get-CimInstance Win32_Process -Filter "Name='memtime.exe'" | ForEach-Object {
  $owner = Invoke-CimMethod -InputObject $_ -MethodName GetOwner
  ($owner.Domain -eq $domain -and $owner.User -eq $user)
} | Where-Object { $_ } | Select-Object -First 1

if (-not $alreadyRunning) {
  Start-Process -FilePath $memtimeExe
}


Deployment via GPO (Scheduled Task)

Deploy the script as a scheduled task via Group Policy.

Path

User Configuration → Preferences → Control Panel Settings → Scheduled Tasks

Action

  1. Program: powershell.exe
  2. Arguments:
    -NoProfile -ExecutionPolicy Bypass -File "\\DOMAIN\SYSVOL\DOMAIN\scripts\Start-Memtime-After-FSLogix.ps1"
  3. Trigger: At log on

  4. Options: Run only when the user is logged on

If you require any further assistance, feel free to contact us at support@memtime.com.