Page 1 of 1

Powershell job: you cannot call a method on a null-valued expression..Exception.Message at

Posted: Wed Jan 29, 2020 9:44 am
by stevens
Hi,

I' m trying to run a script (which takes about 5 minutes) in a powershell job.
PS1 works but not in the job.
Error I get: You cannot call a method on a null-valued expression..Exception.Message at line 6508

Please advise.

Code: Select all

		Logging-Output "Setting path to script"
		$CMOverviewScript = "$ScriptDirectory\CM.ps1"
		Logging-Output "Done"
		
		#if (! $(test-path $CMOverviewScript)){throw "Cannot reach $CMOverviewScript"}
		<# THIS WORKS FINE
		Logging-Output 'Getting CM Details'
		. $CMOverviewScript #Generates $CMApplicationsOverview as global
		$ProcessResults = $CMApplicationsOverview
		Logging-Output 'Done'
		#>
	
		#region jobtracker
		#$progressbaroverlay1.Visible = $true
		Logging-Output -text "Getting CM details as job"
		
		Add-JobTracker -Name 'CM' `
					   -JobScript {
			. $args[0]  #Generates $CMApplicationsOverview as global
			$CMApplicationsOverview 
		}`
						-CompletedScript {Param ($Job)
									$ProcessResults = Receive-Job -Job $Job
									#$ProcessesOutput = $ProcessResults | Out-String			
									#$progressbaroverlay1.Visible = $false
									}`
					   -UpdateScript {	Param ($Job)
									}`
					   -ArgumentList $CMOverviewScript
		
		Logging-Output -text "Done."
		#endregion
		
		$ProcessResults | Out-GridView -Title "SCCM Overview"
		
	
Error => You cannot call a method on a null-valued expression..Exception.Message at line 6508

Re: Powershell job: you cannot call a method on a null-valued expression..Exception.Message at

Posted: Wed Jan 29, 2020 10:12 am
by Alexander Riedel
Which line exactly is 6508?

Re: Powershell job: you cannot call a method on a null-valued expression..Exception.Message at

Posted: Tue Feb 04, 2020 10:31 am
by stevens
I have no clue. The line even does not exist.
Is the syntax of my code correct?

Re: Powershell job: you cannot call a method on a null-valued expression..Exception.Message at

Posted: Thu Feb 06, 2020 10:24 pm
by Nillth
The chances are that it is going to be caused by something in either the .ps1 file or the functions
"$ScriptDirectory\CM.ps1", Logging-Output, Add-JobTracker
are you able to share the full project?
PowerShell_Studio_bFATnZaLLV.png
PowerShell_Studio_bFATnZaLLV.png (15.27 KiB) Viewed 1674 times

Re: Powershell job: you cannot call a method on a null-valued expression..Exception.Message at

Posted: Wed Feb 19, 2020 12:59 am
by stevens
Thanks for the input. I'll leave the job for now and come back to it later.