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

Welcome Forums General PowerShell Q&A SCCM cmdlets output not being able to be put into variable in script

This topic contains 2 replies, has 2 voices, and was last updated by

2 years, 10 months ago.

  • Author
  • #38505

    Points: 3
    Rank: Member

    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
    		[Parameter(Mandatory = $True)]
    		$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 = $($
    				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 $($ -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.

  • #38507

    Points: 0
    Rank: Member

    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 $($| select -expand IsActive)

  • #38514

    Points: 3
    Rank: Member

    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!

The topic ‘SCCM cmdlets output not being able to be put into variable in script’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort