Run AppSense post-logon scripts once per day
Using AppSense to trigger post-logon scripts only once per day means separating event detection from daily execution. AppSense can launch an action when a user logs on, but RDP reconnects, additional Windows sessions, or policy refreshes may cause repeats. An idempotent wrapper gives the business task one controlled run while retaining AppSense’s event-driven model.
The portable pattern is straightforward: AppSense detects the post-logon event, a wrapper compares a stored date with the endpoint’s local date, and the real workload runs only when the marker is stale. The marker is written after success, allowing a failed job to retry on a later sign-in without repeating successful work.
Before editing production, define what “once per day” means. This guide uses once per Windows identity, per endpoint, per local calendar day, triggered by the first eligible logon after midnight. It is not a fixed 09:00 schedule and will not run on a day without a sign-in. Use an AppSense scheduled action when timing matters more than a logon dependency.
Interface labels and script-context options vary across AppSense product generations. Test against the version installed in your environment rather than copying a menu path blindly. Community scripts can save development time, but review each one for execution identity, error handling, data handling, and compatibility with Australian endpoint builds.
Define the daily trigger and scope
Start by separating logon eligibility from the daily-run rule. An unlock or RDP reconnect may not be a new post-logon event, while a sign-in after reboot is. Apply the policy to a pilot group and document whether “user” means Windows identity or person. A user-and-endpoint marker runs on each device; a person-wide rule requires a shared store and raises synchronisation issues.
Bind the AppSense action to the post-logon event and select the correct user or computer context. If your release offers a daily-frequency, once-only, or scheduled option, use it to reduce repeat evaluation, but do not treat it as the only control. Policy refreshes, retries, and updated policy can still produce extra evaluations, so the script must tolerate duplicate calls.
A date-aware wrapper is the most portable pattern across versions. It preserves a genuine logon trigger while the payload enforces the daily limit. The AppSense Exchange community tools collection offers implementations worth comparing, but inspect any download for remote code, hidden execution, unclear elevation, and hard-coded paths before testing.
Build an idempotent daily marker
Place the marker in the scope you chose. For a per-user, per-endpoint rule, use the signed-on user’s HKCU or profile folder and keep the payload in a protected local directory. Confirm that AppSense executes the script as that user; under a system context, HKCU and $env:LOCALAPPDATA may point to the computer account and share one marker across users. An endpoint-wide rule needs computer-scoped storage and a machine-wide lock.
This PowerShell example performs the date check, serialises simultaneous calls for the same profile, runs the payload, and records success:
$stateDir = Join-Path $env:LOCALAPPDATA 'AppSenseExchange'
$stateFile = Join-Path $stateDir 'daily-post-logon.txt'
$lockFile = Join-Path $stateDir 'daily-post-logon.lock'
$payload = 'C:\ProgramData\AppSenseExchange\DailyPayload.ps1'
$today = (Get-Date).Date
New-Item -ItemType Directory -Path $stateDir -Force | Out-Null
$lock = $null
try {
try {
$lock = [IO.File]::Open(
$lockFile,
[IO.FileMode]::OpenOrCreate,
[IO.FileAccess]::ReadWrite,
[IO.FileShare]::None
)
}
catch {
exit 0
}
$lastRun = [datetime]::MinValue
if (Test-Path -LiteralPath $stateFile) {
try {
$lastText = (Get-Content -LiteralPath $stateFile -Raw).Trim()
$lastRun = [datetime]::ParseExact(
$lastText,
'yyyy-MM-dd',
[Globalization.CultureInfo]::InvariantCulture
)
}
catch {}
}
if ($lastRun.Date -ge $today) {
exit 0
}
& $payload
if (-not $?) {
throw 'Daily payload failed.'
}
Set-Content `
-LiteralPath $stateFile `
-Value $today.ToString('yyyy-MM-dd') `
-Encoding ASCII
}
finally {
if ($null -ne $lock) {
$lock.Dispose()
}
}
The marker is written only after successful completion. This allows one successful run per day while permitting a later logon to retry a failed job. If only one attempt is permitted, write the marker before execution and log failures separately, but transient failures will then suppress retries. The lock prevents two sessions for one account from both passing the date check.
Keep the state minimal: one ISO date, no personal data, and no payload output. Retain diagnostics only under the organisation’s privacy and retention rules. When the AppsIOS platform handles mobile workflows, keep those events separate so a phone refresh cannot satisfy or clear the Windows daily marker.
Configure and secure the AppSense policy
Create a dedicated policy instead of extending a broad logon package. Set the event to post-logon, target the intended user groups, and attach only the daily wrapper. Where available, add conditions for managed status, supported Windows versions, network state, or required security software. Avoid volatile conditions, which can defer the action until another sign-in.
Deploy the wrapper and payload through the approved software-distribution channel using versioned, signed files. Keep them on a local path such as C:\ProgramData, rather than a file-server path, to reduce timeout risk on slow or unavailable links. Grant only the permissions needed to read the payload and write the marker. Return a clear exit code so support can distinguish a successful no-op from a failure.
AppSense clients receive policy according to their communication and refresh cycle, so a new policy may first take effect on a later sign-in. Test that delay, and confirm that policy repair or a forced refresh cannot bypass the date guard. If a native schedule is also enabled, document which layer permits the event and which layer decides whether the workload is still required.
Version changes can alter policy scope, action behaviour, and script context. Before rollout, compare the target release with the baseline and use the upgrade planning guide to sequence client updates, compatibility testing, and rollback. Avoid changing server policy, client agents, and the payload in one maintenance window.
Test daily execution and operational controls
Start with a pilot covering managed and offline paths, fast user switching, and RDP. Test the first sign-in, a second sign-in, lock and unlock, disconnect and reconnect, and the first sign-in after the local date changes. Record identity, start time, exit code, marker, and payload result. A successful first run followed by immediate no-op runs is the expected pattern.
Use this trigger checklist:
- Verify the event fires on logon, not unlock.
- Confirm the wrapper runs as the intended Windows user.
- Test policy arrival on offline and newly imaged devices.
- Prove duplicate sessions cannot bypass the lock.
Use this separate operations checklist:
- Test success, timeout, dependency failure, and a missing payload.
- Compare device clocks and correct timezone drift.
- Check daylight-saving and date-rollover behaviour.
- Keep enough logs to diagnose no-ops and failures.
For Chrome policy refresh or browser sign-in behaviour, use the Google D U O reference to separate browser events from Windows logons; a Chrome refresh is not a new desktop session. Keep names, email addresses, and browser profiles out of the marker. If the payload handles personal information, apply approved privacy and retention requirements to its audit output.
Roll out across Australian sites
Roll out by site and user cohort, expanding after a clean monitoring window. Time zones matter in Australia: Sydney and Melbourne observe AEDT during daylight-saving periods, Brisbane remains on AEST, and Perth remains on AWST. A wrapper that compares UTC dates with local dates can run twice or miss a day around transitions, even when the marker logic is otherwise sound.
Plan for state and territory public holidays and hybrid work. A long weekend may leave endpoints without an eligible logon. Decide whether stale work should be skipped, retried, or handled separately. A roster report may be pointless after a full business week, while a security inventory refresh may need an age-based override; keep that decision outside the simple daily marker.
For the business case, include implementation and support effort in Australian dollars and name the owners of AppSense policy, endpoint deployment, and payload failures. Localisation, servicing windows, and regional support hours can expose risks that a single-site test misses. Before publication, compare notes in the AppSense Exchange community forums using the same AppSense version, logon event, and identity context.
Build the wrapper first, apply it to one test account, and validate the marker before publishing an AppSense post-logon policy. Record the chosen scope, product version, payload path, retry behaviour, and rollback action in the change plan. After the pilot confirms one successful run per local day, promote the same tested package to each Australian site and monitor the first week for duplicate or missed executions.