I have a PowerShell script that run .exe from command prompt with argument parameter.
When I run the .exe fromcommand from command promp it working well and the .exe insert some rows in DB
C:\NF\debug>CMExecuter.exe abc.rpr
When I try to run the same command from PowerShell , nothing happen . There is neither error appeared nor rows inserted in DB .please help me as I am confused
I tried the both commands from Powershell and both showed nothing .
solution :1
& "C:\NF\debug\CMExecuter.exe" "abc.rpr"
solution :2
Start-Process -FilePath "C:\NF\debug\CMExecuter.exe" -ArgumentList "abc.rpr"
Maybe your command prompt and powershell has different rights?
Please test this the following way: if your command executes well from a command prompt, start the powershell from that command prompt (by typing powershell and enter) and test your ps command from that powershell.
Related
I am working on script "executeAll.ps1" that would execute multiple "execute.ps1" scripts. I am trying to capture the outputs of each execute.ps1 window but the problem is that the script execute .sql commands from a dacpac and the PRINTS only shows in the powershell window but not in any of my output files.
I have tried having *>> in my executeAll script and Start-Transcript in execute.ps1, but neither of them shows the sql PRINTS.
Is there anything I can do about this, maybe a different approach I am unaware of?
I have access to the .ps1 files, but only a maybe on the .sql files.
Here is my code when executing the script:
Start-Process powershell "& .\execute.ps1 -dbserver $server -databasename $database -client $client *>> "".\output\$client.txt"""
I have a powershell script getting all the computers from WSUS using PoshWSUS. I manually execute the script after opening Powershell in admin mode.
I have to execute the script using SSIS now. I have inserted Execute Process Task in Control Flow. The executable is set as C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
This is the argument: -NoProfile -ExecutionPolicy ByPass -command ". c:\mypath\GetWSUSList.ps1" -verb runAs
I've tried many others, mostly including in this page: PowerShell: Running a command as Administrator
But none of them worked and still getting Unauthorization error. Any help would be appreciated.
I found this link Automate Running PowerShell Scripts that Require Admin elevation via SSIS. It seems similar to the issue you have, so you might be able to use this as a reference.
Here is the solution below:
Step 1: Create a powershell script file. My script.ps1 is:
import-module poshwsus
ForEach ($Server in Get-Content $WSUSServers)
{
& connect-poshwsusserver $Server -port $WSUSPort | out-file $ProcessLog -append
& Get-PoshWSUSUpdateSummaryPerClient -UpdateScope (new-poshwsusupdatescope) -ComputerScope (new-poshwsuscomputerscope) | Select Computer, LastUpdated | export-csv -NoTypeInformation -append $FileOutput
}
Step 2: Create a .bat file, let's say it is called RunMyPS1.bat, like below.
#ECHO OFF
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "& {Start-Process PowerShell -ArgumentList '-NoProfile -ExecutionPolicy Bypass -File ""C:\Scripts\WSUSReport\script.ps1""' -Verb RunAs}"
PAUSE
Note that using -verb runAs at the end of the argument line is very important here.
Step 3: Create a Task Scheduler to run your .bat file, named "RunMyBat" for example.
Open Task Scheduler, click "Create Task" on the right menu. Under General, make sure the checkbox Run with highest priveleges is checked, this is very important. Then navigate to Actions section, add new action by browsing to your .bat file.
Step 4. Run your task scheduler via SSIS
Add "Execute Process Task" to your Control Flow. Make sure the executable of the task is set to: "C:\Windows\System32\schtasks.exe" and the arguments is: "/run /TN "RunMyBat" like below.
Step 5. Run your SSIS package.
Important: Note that after the "execute process task" running the task scheduler is triggered, SSIS directly comes to the next step (if any) without waiting the task scheduler completes its process. Therefore, if there is any tasks that will use the output or updated data by your PowerShell script, then insert a "Script Task" and add sleep to ensure that your powershell script is completed.
System.Threading.Thread.Sleep(120000);
Can anyone help me with run command to open PowerShell as different user?
Currently I am trying to run below command
Runas /noprofile /user:domain\username powershell
It works but I have to provide password once powershell window opens, is there any way where I can directly put password in run command?
Or even if I get to know how can I run any commands from PowerShell using different user without opening new ps window. e.g need to run below command using different user.
Restart-Server -Name testservice
You could try schtasks.exe. You can get the help using schtasks.exe /?
If you are getting any errors after using this command referring the examples, update the post with the error, we are here to help you.
Update:
There is an in-built cmdlet available in PowerShell Register-ScheduledTask, but its depended on OS and is available only from Windows Server 2012 onwards.
The following PSQL command works on Mac/Linux:
psql "dbname='public' user='myuser' password='XXXXXX' host='some.host.com' port='5432'" --file=permissions.sql
But when I try to use the same command on windows, it will login but not execute permissions.sql. I tried changing permissions.sql to \dbbackup\permissions.sql so that I would specify the the full path to the sql script. That didn't appear to help.
When I run the command in Linux, psql logs into the db and executes the script. The same command logs me in to the db but doesn't execute. I just get a command prompt like this: DATABASENAME=>
Then I have to execute \q to logout.
Any suggestions are greatly appreciated.
I want to automate the export process which I take using expdp command in Oracle.
Following is the contents of batch file I have created to open PuTTY.
#echo off
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m Open_Putty.txt`
Following is the contents of Open_Putty.txt to execute different commands.
echo $ORACLE_SID;
Read oraenv;
But after opening Open_Putty.bat it disappears without showing any output.
Please help me with this. I want to set oraenv and run some more commands to take the backup.
It's unlikely that plink.exe disappears without showing any output. I assume you execute the batch file from a Windows Explorer or other GUI application, so the Plink console window disappears once Plink finishes (possibly with error) and you cannot read the output (error).
Make sure you execute plink.exe from a console window (typically a cmd.exe) or add pause command to the end of the batch.
Make sure Plink can find the script file (Open_Putty.txt). As you do not specify a path to the file, it has to be located in your current working directory. Safer is to use a full path to the script file:
"C:\Program Files\PuTTY\plink.exe" username#Ip_Addr -pw password -m "C:\path\Open_Putty.txt"
The backtick symbol at the end of the command should probably not be there.
The name "Open PuTTY" is bit confusing. You are not using PuTTY at all. And even if you refer to Plink by "PuTTY", your script file (Open_Putty.txt) is not opening PuTTY nor Plink. It's executing remote commands. So you should better name it export.txt or similar.