Syntax error when targeting win 7

I’m making a software deployment fixlet that uses Powershell core to test a system’s ability to talk to a server before deploying the package, It works perfect on windows 10 returning an error code if the port is blocked, and installing if its open.

However when targeting a windows 7 box, BF does not run the fixlet, and returns a syntax error of this line:
if{(it contains "False") of lines containing "TcpTestSucceeded" of file "C:\windows\temp\bigfix_test_powershell.txt"}

Does anyone know why this might be? here is the full action script

//Prefetch
prefetch 333573349cf680f43f8ce1cf6215205ba73c26e7 sha1:333573349cf680f43f8ce1cf6215205ba73c26e7 size:758659188 http://LAB-GLD-BFX.ops.lab.local:52311/Uploads/333573349cf680f43f8ce1cf6215205ba73c26e7/acronisinstaller.tmp sha256:6fdce4dcec423350a92622bbc6d58d995582595be4fde70bc865e1e9d8712e96

// Cache Powershell Core Runtime
parameter "PowershellDir"="{pathname of data folder of client}/__Global/Verve/Asset Discovery/Runtime/7.1.0-p5"

if {not exists folder (parameter "PowershellDir")}

	folder create "{parameter "PowershellDir"}"
	
	if { Windows of Operating System }

		prefetch unzip.exe sha1:e1652b058195db3f5f754b7ab430652ae04a50b8 size:167936 http://software.bigfix.com/download/redist/unzip-5.52.exe SHA256:8D9B5190AACE52A1DB1AC73A65EE9999C329157C8E88F61A772433323D6B7A4A

		if{x64 of operating system}
			prefetch PSCore.zip sha1:81B3FCDA2DF7B2F67B7DB6B7F4F618EDADCA58D9 size:100133000 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/PowerShell-7.1.0-preview.5-win-x64.zip sha256:87E318629B478DFB8B0F65C1D6F964943F3AD54185AAF9662A8D21F4E6FDA1F1
		else
			prefetch PSCore.zip sha1:58E9B96BA05EE08A5E414C112202475CD70085B1 size:90494207 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/PowerShell-7.1.0-preview.5-win-x86.zip sha256:F92FB9F03C0A033642A5F1E87E0517872D4D3F27CED0A80EDCB9C4F81636419D
		endif
		waithidden __Download\unzip.exe -o "{pathname of client folder of current site}\__Download\PSCore.zip" -d "{parameter "PowershellDir"}"

	elseif {Unix of Operating System} 

		prefetch PSCore.tar.gz sha1:3D1B1825EA36AAB9AA725E9CE9CCBC64029DE45B size:68635738 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/powershell-7.1.0-preview.5-linux-x64.tar.gz sha256:F58FE99DDF456C3D987E50F1486A805A56A1A6DDF1CA2B9F2E39974181E17DFC

		wait tar xzf "__Download/PSCore.tar.gz" -C "{parameter "PowershellDir"}"

	else
		exit 10
	endif
endif


//TEST CONNECTION TO MANAGEMENT SERVER 
//Run port test 
delete C:\windows\temp\bigfix_test_powershell.txt 
action uses wow64 redirection false

waithidden "{pathname of file whose (name of it = "pwsh" or name of it = "pwsh.exe") of folder (parameter "PowershellDir")}" -ExecutionPolicy Bypass -command "Test-NetConnection XXX.XXX.XXX.XXX -p XXXX |Out-File "C:\windows\temp\bigfix_test_powershell.txt" 

action uses wow64 redirection {x64 of operating system}

//analyze result 
if{(it contains "False") of lines containing "TcpTestSucceeded" of file "C:\windows\temp\bigfix_test_powershell.txt"}
exit 9 
endif 

if{(it contains "True") of lines containing "TcpTestSucceeded" of file "C:\windows\temp\bigfix_test_powershell.txt"}
//createfile until _end_
//success
//_end_
//move __createfile c:\temp\success.txt
extract 333573349cf680f43f8ce1cf6215205ba73c26e7
wait "{pathname of system folder & "\msiexec.exe"}" /i "{(pathname of client folder of current site) & "\__Download\AB64.msi"}" /qn /l*v install.log TRANSFORMS="{(pathname of client folder of current site) & "\__Download\AB64.msi.mst"}"

endif

Have you tried running the PowerShell manually? I’m not sure that the Test-NetConnection module was even available in PowerShell on Win7

That does seem to be the problem. I’m still confused as to why BF didn’t attempt the other steps though. It just told me it has a syntax error at that line. The status did not show “completed” on any line.

I had some other issues on the test box which I’ve worked out, you were right, that the powershell command and the powershell core command do not match up. Putting powershell core on the system and manually running
pwsh.exe -ExecutionPolicy Bypass -command "Test-Connection XX.XXX.XXX.XXX -TcpPort XXX |Out-File "C:\windows\temp\bigfix_test_powershell.txt"

Does create a single line true false file. Unfortunately, the IF statement still kicks a syntax error, and the fixlet is not processing the commands before that point. No prefetch happens, so PWSH.exe can’t run, so the file cant be created. Is there a method for ignoring syntax errors like this that come up before the script has processed?

New script for reference:
//Prefetch
prefetch 333573349cf680f43f8ce1cf6215205ba73c26e7 sha1:333573349cf680f43f8ce1cf6215205ba73c26e7 size:758659188 http://LAB-GLD-BFX.ops.lab.local:52311/Uploads/333573349cf680f43f8ce1cf6215205ba73c26e7/acronisinstaller.tmp sha256:6fdce4dcec423350a92622bbc6d58d995582595be4fde70bc865e1e9d8712e96

// Cache Powershell Core Runtime
parameter "PowershellDir"="{pathname of data folder of client}/__Global/Verve/Asset Discovery/Runtime/7.1.0-p5"

if {not exists folder (parameter "PowershellDir")}

	folder create "{parameter "PowershellDir"}"
	
	if { Windows of Operating System }

		prefetch unzip.exe sha1:e1652b058195db3f5f754b7ab430652ae04a50b8 size:167936 http://software.bigfix.com/download/redist/unzip-5.52.exe SHA256:8D9B5190AACE52A1DB1AC73A65EE9999C329157C8E88F61A772433323D6B7A4A

		if{x64 of operating system}
			prefetch PSCore.zip sha1:81B3FCDA2DF7B2F67B7DB6B7F4F618EDADCA58D9 size:100133000 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/PowerShell-7.1.0-preview.5-win-x64.zip sha256:87E318629B478DFB8B0F65C1D6F964943F3AD54185AAF9662A8D21F4E6FDA1F1
		else
			prefetch PSCore.zip sha1:58E9B96BA05EE08A5E414C112202475CD70085B1 size:90494207 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/PowerShell-7.1.0-preview.5-win-x86.zip sha256:F92FB9F03C0A033642A5F1E87E0517872D4D3F27CED0A80EDCB9C4F81636419D
		endif
		waithidden __Download\unzip.exe -o "{pathname of client folder of current site}\__Download\PSCore.zip" -d "{parameter "PowershellDir"}"

	elseif {Unix of Operating System} 

		prefetch PSCore.tar.gz sha1:3D1B1825EA36AAB9AA725E9CE9CCBC64029DE45B size:68635738 https://github.com/PowerShell/PowerShell/releases/download/v7.1.0-preview.5/powershell-7.1.0-preview.5-linux-x64.tar.gz sha256:F58FE99DDF456C3D987E50F1486A805A56A1A6DDF1CA2B9F2E39974181E17DFC

		wait tar xzf "__Download/PSCore.tar.gz" -C "{parameter "PowershellDir"}"

	else
		exit 10
	endif
endif


//TEST CONNECTION TO MANAGEMENT SERVER 
//Run port test 
delete C:\windows\temp\bigfix_test_powershell.txt 
action uses wow64 redirection false

waithidden "{pathname of file whose (name of it = "pwsh" or name of it = "pwsh.exe") of folder (parameter "PowershellDir")}" -ExecutionPolicy Bypass -command "Test-Connection XXX.XXX.XXX.XXX -TcpPort XXXX |Out-File "C:\windows\temp\bigfix_test_powershell.txt" 

action uses wow64 redirection {x64 of operating system}

//analyze result 
if{(it contains "False") of Line 1 of file "C:\windows\temp\bigfix_test_powershell.txt"}
exit 9 
endif 

if{(it contains "True") of Line 1 of file "C:\windows\temp\bigfix_test_powershell.txt"}
//createfile until _end_
//success
//_end_
//move __createfile c:\temp\success.txt
extract 333573349cf680f43f8ce1cf6215205ba73c26e7
wait "{pathname of system folder & "\msiexec.exe"}" /i "{(pathname of client folder of current site) & "\__Download\AB64.msi"}" /qn /l*v install.log TRANSFORMS="{(pathname of client folder of current site) & "\__Download\AB64.msi.mst"}"

endif

I think you may be getting into a troublesome edge case, where the client has to evaluate all of the Relevance substitutions in the script before the script executes - in case any of those are used in building a download file that needs to be prefetched before the action executes. But if any of those relevance statements throw an error (like the file doesn’t exist yet, because your action hasn’t written it), the action terminates without ever executing.

The hard workaround is to change all of your relevance statements so they don’t throw an error during pre-execution evaluation. It’s ok for them to have an empty result, but not ok to throw an error. The singular {(it contains "False") of Line 1 of file "C:\windows\temp\bigfix_test_powershell.txt"} will throw an error if the text file does not exist, while the plural {(it contains "False") of Lines 1 of files "C:\windows\temp\bigfix_test_powershell.txt"} should just give an empty result rather than an error (and allow the pre-execution evaluation to succeed).

The easy way is to create a Prefetch Block and put all of your downloads there. When there is a Prefetch Block, only the substitutions in the Prefetch Block itself are evaluated before the action starts, all the other substitutions outside of the block would then only evaluate while the action is executing.

A little more detail on this at

1 Like

Unfortunately, pluralizing the if statements did not work.

The prefetch block took some wrangling to get the add prefetch item line happy, but it worked enough to run the commands all the way to the actual installer. So it looks like that’s done the trick.

Thanks Mr Wizard!

2 Likes