How to use SSISDeploy command in powershell script - powershell

I'm running SSISDeploy command (documentation is here) in my CMD:
SSISDeploy.exe -s:"download\Integration Services.ispac" -d:catalog;/SSISDB/TEST/DEVOPS;"TEST03,1234" -at:win
all working good, and now I need to run it thought powershell script (against windows server 2019 slave), so I tried this syntax:
$SSISDeploy = Start-Process -FilePath SSISDeploy.exe -ArgumentList '/source:"download\Integration Services.ispac"',"/destination:catalog;${Target};"${Env}"" -at:win -wait -PassThru -Credential $cred -RedirectStandardOutput ssisstdout.txt -RedirectStandardError ssisstderr.txt
but it fails with exception:
Start-Process : A positional parameter cannot be found that accepts argument 'TEST03,1234'.
+ ... SISDeploy = Start-Process -FilePath SSISDeploy.exe -ArgumentList '/so ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
Can you suggest what's wrong with the syntax?

$StartProcessProps = #{
FilePath = 'SSISDeploy.exe'
ArgumentList = '-s:"download\Integration Services.ispac" -d:catalog;{0};{1} -at:win' -f $Target, $Env
Wait = $true
PassThru = $true
Credential = $cred
RedirectStandardOutput = 'ssisstdout.txt'
RedirectStandardError = 'ssisstderr.txt'
}
$SSISDeploy = Start-Process #StartProcessProp

Related

Using Powershell to download and run exe file

I am trying to download Malwarebytes Anti-Rootkit Beta but my PowerShell script throws the error below. How do I fix this?
My Script:
$url = "https://data-cdn.mbamupdates.com/web/mbar-1.10.3.1001.exe"
$outpath = "$PSScriptRoot/mbar-1.10.3.1001.exe"
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $outpath)
$args = #("Comma","Separated","Arguments")
Start-Process -Filepath "$PSScriptRoot/mbar-1.10.3.1001.exe" -ArgumentList $args
The Error:
Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At line:8 char:1
+ Start-Process -Filepath "$PSScriptRoot/mbar-1.10.3.1001.exe" -Argumen ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand

How to use -ArgumentList with Invoke-Command to pass flags to a script?

How to use -ArgumentList with Invoke-Command to pass flags to a script?
# File: ./setup.ps1
param(
[Parameter(Mandatory=$false)]
[alias("force")]
[switch]$opt_force
)
if ($opt_force) {
write-host "FORCING something!"
}
write-host "Done"
Powershell Command Line:
PS> Invoke-Command -Computer pv3039 -FilePath ./setup.ps1 -ArgumentList "-force"
Error Message:
positional parameter cannot be found that accepts argument '-force'.
+ CategoryInfo : InvalidArgument: (:) [], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound
+ PSComputerName : pv3039
If you want to call a remote script, you can use Start-Process instead of Invoke-Command. Maybe you can try something like this.
Start-Process PowerShell -ArgumentList "YOUR_SCRIPT_PATH\setup.ps1 -Force" -NoNewWindow -Wait
This way it can accept parameters from the called script.

Jenkins and powershell. Download file

I have a script in Powershell and want to run this on many servers.
It's running from Jenkins via a Powershell step, the input param $env:servers
Simple example:
$SrvPassword = ConvertTo-SecureString -String "$($ENV:SlavePassword)" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ("$ENV:SlaveUser", $SrvPassword)
Invoke-Command -Computername $env:servers -ScriptBlock {
$client = New-Object System.Net.WebClient
$client.DownloadFile("\\server1.domain.ru\123\123.zip","C:\123.zip")
} -Credential $cred
But when I build it with parametrs, i got error:
[firstDeploy] $ powershell.exe -NonInteractive -ExecutionPolicy ByPass "& 'C:\Users\ADMINI~1\AppData\Local\Temp\jenkins6658148949844825772.ps1'"
Exception calling "DownloadFile" with "2" argument(s): "Access to the path '\\server1.domain.ru\123\123.zip' is denied."
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
+ PSComputerName : server2.domain.ru
When i do this without jenkins all work fine. Share full access. What's wrong?

Make Choices to Enable / Disable Net Adapter Using Powershell

I'm Trying to use Powershell to make a choices to Enable/Disable Net Adapter "Ethernet"
I Coded This
$caption = "Choose Action";
$message = "What do you want to do?";
$enab = start-process powershell -verb runas -argument D:\ena.ps1
$disa = start-process powershell -verb runas -argument D:\dis.ps1
$choices = [System.Management.Automation.Host.ChoiceDescription[]]($enab,$disa);
$answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
switch ($answer){
0 {"You entered Enable"; break}
1 {"You entered Disable"; break}
}
Error :
Object cannot be stored in an array of this type.
At D:\Untitled4.ps1:5 char:1
+ $choices = System.Management.Automation.Host.ChoiceDescription[];
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], InvalidCastException
+ FullyQualifiedErrorId : System.InvalidCastException
Exception calling "PromptForChoice" with "4" argument(s): "Value
cannot be null. Parameter name: choices" At D:\Untitled4.ps1:6 char:1
+ $answer = $host.ui.PromptForChoice($caption,$message,$choices,0)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
I have failed before this to do On/Off script using powershell (if the net adapter is enable then disable it and vice versa. is there any way to do this?
Using this: https://technet.microsoft.com/en-us/library/ff730939.aspx I think what you want to be doing is the following:
$caption = "Choose action:"
$message = "What state do you want for the network adapter?"
$enable = New-Object System.Management.Automation.Host.ChoiceDescription "&Enable", `
"Enables the Network Adapter"
$disable = New-Object System.Management.Automation.Host.ChoiceDescription "&Disable", `
"Disables the Network Adapter"
$options = [System.Management.Automation.Host.ChoiceDescription[]]($enable, $disable)
$result = $host.ui.PromptForChoice($caption, $message, $options, 0)
switch ($result)
{
0 {
"You selected Enable."
start-process powershell -verb runas -argument D:\ena.ps1
}
1 {
"You selected Disable."
start-process powershell -verb runas -argument D:\dis.ps1
}
}
The approach you were taking wasn't working because you were trying to assign a process to a ChoiceDescription array. In the example above, you have to first create two ChoiceDescription objects before assigning them to the array

Start-Process gives error

Here's the code
$tool = "E:\Experiments\Popup\latest\xperf.exe"
$toolOutput = "XPerfOutput.log"
$toolError = "XPerfError.log"
$command = "-stop"
$x = Start-Process -FilePath $tool -ArgumentList $command -RedirectStandardOutput $toolOutput -RedirectStandardError $toolError -WindowStyle Hidden -PassThru -Wait
And Here's there error:
Start-Process : Parameter set cannot be resolved using the specified named parameters. At E:\Experiments\Popup\asd.ps1:9 char:1
+ Start-Process -FilePath $tool -ArgumentList $command -RedirectStandardOutput $toolOutput RedirectStandardError $toolError -WindowStyle Hidden
-PassThru -Wait
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.StartProcessCommand
I want to run the process in a hidden window, wait for it to return and get the error, output and exit code.
According to the documentation for Start-Process, the combination of the redirection parameters (RedirectStandardOutput and RedirectStandardError) and the WindowStyle parameter is invalid since they exist in separate parameter sets.
This means that they cannot be used together. This is why you're receiving that particular error.