Quantcast
Channel: Configuration Manager 2012 - Application Management forum
Viewing all articles
Browse latest Browse all 4762

SCCM Script detection method not working.

$
0
0

Hi All,

I am trying to deploy an application  upgrade to an application which was previously installed to %PRogramFiles% and the upgrade installs to the current logged in user (%LOCALAPPTATA%. I borrowed a detection script someone had written to install MS Teams which I had modified in the past to work with other applications.

When I test the script on a system running on a local system and running a admin CMD and launching PSExec to simulate running in the System Context and I get the following error is what I receive:

C:\Temp>powershell.exe -ExecutionPolicy bypass -file .\WPDetectionScript.ps1
At C:\Temp\WPDetectionScript.ps1:22 char:12
+ Write-Log "Start Script Execution"
+            ~~~~~
Unexpected token 'Start' in expression or statement.
At C:\Temp\WPDetectionScript.ps1:37 char:67
+ ...    Write-Log "Warning: WorkPace.exe not found – need to install App!"
+                                                                         ~
The string is missing the terminator: ".
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : UnexpectedToken

I know the issue is in the $WorkPace declaration on Line 20. There is a space in the path but I can't figure out where to put the ~ in the path for the script verify if the file is present.

Here is the Script

[String]$LogfileName = "WorkPaceDetection"
[String]$Logfile = "$env:TEMP\$LogfileName.log"
Function Write-Log
{
	Param ([string]$logstring)
	If (Test-Path $Logfile)
	{
		If ((Get-Item $Logfile).Length -gt 2MB)
		{
			Rename-Item $Logfile $Logfile".bak" -Force
		}
	}
	$WriteLine = (Get-Date).ToString() + " " + $logstring
	Add-content $Logfile -value $WriteLine
}

$User = gwmi win32_computersystem -Property Username
$UserName = $User.UserName
$UserSplit = $User.UserName.Split("\")
$WorkPace = "$env:SystemDrive\users\" + $UserSplit[1] + "`\appdata\local\Wellnomics\Wellnomics WorkPace\WorkPace.exe`"
# Parameter to Log
Write-Log "Start Script Execution"
Write-Log "Logged on User: $UserName"
Write-Log "Detection-String: $WorkPace"
If (Test-Path $WorkPace)
{
	Write-Log "Found DetectionFile"
	$MSTeams = Get-Item $WorkPace
	Write-Log "Get File Details"
	Write-Log "Version found: $($WorkPace.VersionInfo.FileVersion)"
	Write-Log "Script Exectuion End!"
	Write-Log ""
	Return $true
}
Else
{
	Write-Log "Warning: WorkPace.exe not found – need to install App!"
}


Viewing all articles
Browse latest Browse all 4762


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>