PowerShell execute Sqlpackage.exe remotely

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of powershelluser143 powershelluser143 3 months, 2 weeks ago.

  • Author
    Posts
  • #63922
    Profile photo of powershelluser143
    powershelluser143
    Participant

    I am trying to execute the sqlpackage.exe remotely as follows
    $SqlPackage = "C:\SqlPackage.exe"
    [string[]] $Properties = @("/p:DropObjectsNotInSource=true","/p:ScriptDatabaseCompatibility=true","/p:CommandTimeout=0", "/p:RegisterDataTierApplication=true")

    $Params=@("/Action:Publish","/TargetServerName:""$ServerInstance""","/TargetDatabaseName:""$TargetDatabaseName""","/SourceFile:""$SourceFile""","$Variables")

    $p="$Params $Properties"
    Invoke-Command -ScriptBlock {& $SqlPackage } -ArgumentList @p -Session $session

    But I got an exception as follows

    A positional parameter cannot be found that accepts argument 'A'.
    So can some one help me how to resolve

  • #63928
    Profile photo of Daniel Krebs
    Daniel Krebs
    Moderator

    Please try below:

    Invoke-Command -Session $session -ScriptBlock { Start-Process -NoNewWindow -Wait -FilePath ${Using:SqlPackage} -ArgumentList "${Using:Params} ${Using:Properties}" }
    
  • #64065
    Profile photo of powershelluser143
    powershelluser143
    Participant

    Hi Daniel I am getting an error as file not found, to be more clear I need to install on B machine and I am running the script from A machine where the two machines are remotely connected.

    $SqlPackage = "C:\SqlPackage.exe"

    this path is from A machine

You must be logged in to reply to this topic.