SCCM cmdlets output not being able to be put into variable in script

I have an interesting situation with SCCM cmdlets. I am hoping somebody can help me with this situation.

I am trying to get the ISactive property result out of Get-CMDevice.

I have created a custom script and can get a object out of sccm.
I can even produce a variable.

function Get-SCCMDeviceinfo
{
	Param
	(
		[Parameter(Mandatory = $True)]
		[String]$Computername
	)
	Process
	{
		
		$CMModule = import-module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
		$CMSiteCode = 'PRM'
		
		$CMSiteCode = $CMSiteCode + ":"
		Import-Module "C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1"
		Set-Location $CMSiteCode
		
		Get-CMDevice -name $Computername
		Set-Location c:\
	}
	
	
}

In the CLI it works. I get the result that I want. I use get-member I get output to say what properties are there.

Yet when I run the custom cmdlet in a script or even Get-CMDevice (doing the manual steps stepping through to the CMSite) it comes up with a blank value,

I have the hash table in question below in which I am using the output. Everything works apart from that single entry on ‘SCCMAgentActive’:
The other hash table is actually being pulled from a custom xml of a system report being generated by another script.

$Systeminformation = [Ordered]@{
				Computername = $($SavedSystemReport.name)
				NumberofCores = $($SavedSystemReport.numCPU)
				Operatingsystem = $($SavedSystemReport.OperatingSystem)
				RegionalSetting = $($SavedSystemReport.RegionalSetting)
				ActiveDirectoryDomainName = $($SavedSystemReport.Domain)
				ActiveDirectoryOrganizationalUnit = $($SavedSystemReport.OrganizationalUnit)
				CDROMDriveLetter = $($SavedSystemReport.OpticalDrive) | select -ExpandProperty driveletter
				LocalComputerDescription = $($SavedSystemReport.Description) | Select -ExpandProperty Description
				ActiveDirectoryDescription = $(Get-ADComputer -identity $($SavedSystemReport.name) -Properties description | select -expand description)
				SCCMAgentActive = $(Get-SCCMDeviceinfo -Computername $Computer| select -expand IsActive)
				ServicePack = $($SavedSystemReport.ServicePack)
				TimeServiceRunning = $($SavedSystemReport.TimeserviceRunning)
				SystemManagedPageFile = $($SavedSystemReport.AutomaticManagedPageFile)
				Ram = "{0:N02}" -f $($SavedSystemReport.RAM/1GB)
			}

Any help appreciated.

I do not see an issue with your function. I am am to use it from the cli and within a script.
Are you sure the $computer variable is populated correctly? all of the other values in your hash table are using values from the $SavedSystemReport hash table. Could this be your issue? Have you tried SCCMAgentActive = $(Get-SCCMDeviceinfo -Computername $($SavedSystemReport.name)| select -expand IsActive)

Johnathan , you are correct. I rechecked my values again and found that the $computer value is not what I thought it was. It was actually an xml file name. I’m going to have to reread the debugging feature of powershell again. Thanks for pointing me in the right direction on both accounts!