SCCM - PS - Detection Method for User APPDATA

I needed a detection method to confirm the presence of a file under the %APPDATALOCAL% directory and a HKCU registry key. Thanks to this post and this one I was able to achieve this.

#Detects if C:\Users\%username%\Appdata\Roaming\folder_name\file_or_subfolder_name exists

Function CurrentUser{
#CurrentUser function converts the username object string "@{username=domain\user}" 
#         to the exact logon string "user" like the example below
#@{username DOMAIN\USER}
$loggedInUserName = get-wmiobject win32_computersystem | select username
$loggedInUserName = [string]$loggedInUserName
$loggedinUsername = $loggedInUserName.Split("=")
$loggedInUserName = $loggedInUserName[1]
$loggedInUserName = $loggedInUserName.Split("}")
$loggedInUserName = $loggedInUserName[0]
$loggedInUserName = $loggedInUserName.Split("\")
$loggedInUserName = $loggedInUserName[1]
Return $loggedInUserName
$user = CurrentUser

$appPath = "C:\Users\" + $user + "\AppData\Local\Folder\Folder\App.exe"

if( ( Test-Path $appPath) -and ( Test-path "HKCU:\SOFTWARE\Example\ExampleKey" ) )

Write-Host "installed"


Add this to your SCCM detection method but remember you mist sign the script or have your execution policy set to unrestricted :( or you will receive "ps1 is not digitally signed. The script will not execute on the system." errors during AppDiscovery.

Also check out for a VB detection method.