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

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

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

Post 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

User avatar
Alexander Riedel
Posts: 7377
Joined: Tue May 29, 2007 4:43 pm

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

Post by Alexander Riedel »

Which line exactly is 6508?
Alexander Riedel
SAPIEN Technologies, Inc.

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

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

Post by stevens »

I have no clue. The line even does not exist.
Is the syntax of my code correct?

User avatar
Nillth
Posts: 31
Joined: Thu Aug 01, 2013 6:14 pm
Location: Melbourne, Australia

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

Post 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 1134 times

User avatar
stevens
Posts: 416
Joined: Wed Jun 15, 2016 2:26 am

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

Post by stevens »

Thanks for the input. I'll leave the job for now and come back to it later.

Locked