Issue with free module Making Historical and Trend Reports in PS

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 3 years, 10 months ago.

  • Author
    Posts
  • #7272
    Profile photo of Ben Morris
    Ben Morris
    Participant

    Hi Guys,

    I have been reading through the excellent free eBooks published by Don Jones and am very interested to make use of the  modules provided with 'Making Historical and Trend Reports in PowerShell'. Whilst I was able to quickly get both the 'get' and 'save' commands working pretty quickly I did unfortunately confirm the module does require v3 to work correctly and the production server I need to use them on is Server 2003 so can only support PS v2.0. My solution to this is to for the first time attempt to within a script use implicit remoting to enable the execution of these modules remotely. The issue I have encountered is when I run my script on my 2003 Server I get the following error...

    Save-ReportData Error Message: (See attached screen capture)

    Invoke-Command : Illegal type name on input object – aborting – please read the book!

    I have been able to successfully get database table results whilst in the debug mode of my script copied below using the Get-ReportData however I get errors when attempting to pass and object containing new table data to the Save-ReportData command. As the Get-ReportData is working I know the module is working over the implicit remoting session.

    My issue appears to be the custom $object I created isn't being piped correctly to the Save-RemReportData module with the ‘type name’ intact. When I do a Get-Member on $Object I can visually confirm the type name exists and is correctly formatted.

    This is quite frustrating as I am very keen to get a handle on how to utilize these free modules so in future I can have scripts log to an SRS DB for much easier monitoring of automated solutions.

    Does anyone have any suggestions???

    Also please don't critique the current script too much, I am just in the process of getting base functionally working. 😉

     PS1 SCRIPT

    < # 05/06/2013 Ben Morris The purpose of this script is to set SCCM instance rights for new 'Software Distribution' (SD) collections to enable remote teams more granular access to the SCCM central site server. /#>

    PARAM
    (
    [Parameter(Position=1)] $siteCode,
    [Parameter(Position=2)] $CollID,
    [Parameter(Position=3)] $UserName
    )

    $DebugPreference = 'Inquire'
    Import-Module SCCM
    Import-Module SCCM_Permissions
    Import-Module Get-SCCMCollectionPath

    Connect-SCCMServer SCCMSERVER01
    New-SCCMConnection SCCMSERVER01

    If($siteCode -eq 'CSS')
    {
    $colName = get-wmiobject -query "SELECT * FROM SMS_Collection where CollectionID = '$CollID'" -namespace "root\sms\site_css"
    If($($ColName.Name) -match 'SD')
    {
    $Update = New-SCCMInstancePermission -SccmServer SCCMSERVER01 -InstanceID "$CollID" -InstancePermission 2 -ObjectKey 1 -UserName "domain\group"
    Add-Content -Path D:\Scripts\Set_SD_Collection_Instance_Rights\Activity_Success.log -value "ChangeTime: $(Get-Date -Format g) SiteCode: $SiteCode UserName: $UserName CollectionID: $CollID CollectionName: $($ColName.Name) Result: $Update CollectionPath: $($(Get-SCCMCollectionPath $CollID) | Out-String)"

    $Pass = ConvertTo-SecureString -string "NotaRealPassword" -asplaintext -force
    $Creds = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist "domain\someaccount", $Pass

    $Session = New-PSSession -computerName SERVER02 -Credential $Creds #Server with PSv3 and SQL reporting modules.
    Invoke-command { import-module SQLReporting } -session $Session
    Export-PSSession -session $session -commandname *-ReportData* -outputmodule RemSQLReporting -allowclobber -Force
    Import-Module RemSQLReporting -prefix Rem

    #Logging Permission Changes to SRS reporting DB.
    $object = New-Object PSObject
    $object.PSObject.TypeNames.Insert(0,'Report.Coll_Rights_Update')
    $object | Add-Member –MemberType NoteProperty –Name CollectionID –Value "$CollID"
    $object | Add-Member –MemberType NoteProperty –Name UserName –Value "$UserName"
    $object | Add-Member –MemberType NoteProperty –Name Result –Value "$Update"
    $object | Add-Member –MemberType NoteProperty –Name CollectionName –Value "$($ColName.Name)"
    $object | Add-Member –MemberType NoteProperty –Name ChangeTime –Value "$(Get-Date -Format g)"
    $object | Add-Member –MemberType NoteProperty –Name Path –Value "$(Get-SCCMCollectionPath $CollID)"
    write-debug "Stop and check objects?"
    $object | Save-RemReportData -Conn "Server=DBSERVER01;Database=SCCM_TrendReporting;User ID=SCCM_TrendReportingUser;Password=SomeSQLPwd;"

    Remove-PSSession -session $session
    }
    Else
    {
    Add-Content -Path D:\Scripts\Set_SD_Collection_Instance_Rights\Activity_Fail.log -value "ChangeTime: $(Get-Date -Format g) SiteCode: $SiteCode UserName: $UserName CollectionID: $CollID CollectionName: $($ColName.Name) Result: $Update CollectionPath: $($(Get-SCCMCollectionPath $CollID) | Out-String)"
    }
    }

  • #7279
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Objects sent over Remoting get serialized and then de-serialized; I didn't really design the module to understand that. You'd probably be better off just hitting your database directly. The module is really just meant as a "I don't know SQL" shortcut. You clearly do know some SQL though 🙂 and if you access the DB directly then you can run all the code on your server, since you'd just be using the SqlClient .NET classes

You must be logged in to reply to this topic.