locked
Powershell to import CIs not working remotely RRS feed

  • Question

  • Hello,

    We have a runbook that scans a database every day for new objects. It then exports the new objects into a CSV. This CSV is used with an XML file to import custom CI objects. 

    After the CSV is created, the runbook runs a PowerShell script that starts a remote session on the SCSM management server and imports the new CI data using the CSV and the XML. Here is the script:

    $Username = "user@domain.com"
    $Password = "password" | ConvertTo-SecureString -asPlainText -Force
    $Creds = New-Object System.Management.Automation.PSCredential($Username,$Password)
    
    Invoke-Command -ComputerName "SCSMServer" -Credential $Creds -ScriptBlock {
    
        # Importing Service Manager and SMLets Modules
    Import-Module "E:\Service Manager\Powershell\System.Center.Service.Manager.psd1"
    
        # Import the CSV file
    Import-SCSMInstance –FormatFileName "\\FileShare\OrchShare\Store import\StoreLocationImport.xml" -DataFileName "\\FileShare\OrchShare\Store import\StoreLocations.csv"
    }


    The account running the remote session is an SCSM Admin and an Admin on the server itself.

    The piece of script inside the remote session runs perfectly fine when run locally, but returns an error when I try to run it in a PowerShell session on the Orchestrator server:

    Could not initialize a Management Object Creator from format file \\FileShare\OrchShare\Store
    import\StoreLocationImport.xml. Import thread exiting.
        + CategoryInfo          : OperationStopped: (SITE_SM:EnterpriseManagementGroup) [Import-SCSMInstance], DataException
        + FullyQualifiedErrorId : Unable to import CSV file,Microsoft.EnterpriseManagement.ServiceManager.Cmdlets.ImportInstanceCmdlet
        + PSComputerName        : SCSMServer

    When run in an Orchestrator .NET activity, it doesn't return an error, but there's no new CIs being imported in SCSM. So, clearly it's running into similar issues.

    We had this solution working fine in 2016, but it seems like the move to 1801 has caused issues.

    Any help would be appreciated.

    Thank you!


    Wednesday, February 6, 2019 9:22 PM

Answers

  • Do you have the SCSM console installed on the same server you are usng the Orchestrator on?
    With the remote locations you could try a mapped drive, it might be giving errors due to the unc path

    Website: www.walshamsolutions.com Technical Blog: https://www.walshamsolutions.com/technical-blog Personal Blog: https://www.walshamsolutions.com/personal-blog Twitter: Dwalshampro

    • Marked as answer by Gary Winhoven Tuesday, February 12, 2019 3:31 PM
    Thursday, February 7, 2019 11:36 AM
  • It was the UNC path. Once I put the files on the management server and changed the script so it would use the files on the local directory, it worked like a charm.

    Thank you!

    Tuesday, February 12, 2019 3:32 PM

All replies

  • Do you have the SCSM console installed on the same server you are usng the Orchestrator on?
    With the remote locations you could try a mapped drive, it might be giving errors due to the unc path

    Website: www.walshamsolutions.com Technical Blog: https://www.walshamsolutions.com/technical-blog Personal Blog: https://www.walshamsolutions.com/personal-blog Twitter: Dwalshampro

    • Marked as answer by Gary Winhoven Tuesday, February 12, 2019 3:31 PM
    Thursday, February 7, 2019 11:36 AM
  • It was the UNC path. Once I put the files on the management server and changed the script so it would use the files on the local directory, it worked like a charm.

    Thank you!

    Tuesday, February 12, 2019 3:32 PM