PowerShell executing .bat files with in the same session - powershell

I am installing a software in silent mode using PowerShell. Installation was done successfully but when I am trying to execute few batch files I am getting some exceptions.
Could not find the files for the given pattern. The system can not find the specified path.
My command inside my PowerShell:
$inst_path = \\My installed drive (c:\program files\mysoftware\)
& $inst_path\start-service.bat install
But when I closed the PowerShell ISE and executing the same command it is working without any exceptions, so can someone help me overcome this?

You've got a double slash in the path to the bat file, both the $inst_path variable and the path you construct.
You're trying to call c:\program files\mysoftware\\start-service.bat - which is going to fail.
Try this instead:
$inst_path = "c:\program files\mysoftware"
& "$inst_path\start-service.bat" install

Related

Unable to invoke ssh.exe in PowerShell even on providing the full path via UiPath Studio

The following works on my windows machine using PowerShell
ssh username#example.com
Now, I am trying to run the same command within PowerShell using UiPath Studio for RPA but I get the standard invalid command error -
Invoke Power Shell: the term 'ssh username#example.com' is not recognized as the name of a cmdlet, function, script file, or operable program...
However ssh.exe does exist on the machine and I even tried providing the absolute path, same result.
Are there any additional configurations to be done on the UiPath / system end to make ssh executable via UiPath Studio?
Thanks in advance
I had a similar issue with Invoke-SSH, what I did was to do Import-Module Posh-SSH, but that resulted to:
Import-Module: Could no load file or assembly 'Renci.Ssh.Net
So in UiPath Studio I went to Manage Packages and installed the Nuget package for Renci SSH. Afterwards, the Import worked, and then the Invoke-SSH command worked too.
Got this tip from this video: https://www.youtube.com/watch?v=y2VnY48MJQE&ab_channel=techu

MSBuild from Powershell

I'm trying to run a Sync from MSBuild (From Powershell) that also includes Pre Sync Commands.
I am unable to get the commands right. I've tried multiple ways, but the final way I'm up to is :
[string[]]$msdeployArgs = #(
"-verb:sync",
"-preSync:runCommand='$preSyncCommand',waitInterval=30000",
"-source:dirPath=$sourceFolder",
"-dest:computerName=$serverName,userName=$username,password=$password,authType=basic,dirPath=$serviceFolder",
"-postSync:runCommand=$postSyncCommand,waitInterval=30000"
)
& "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" $msdeployArgs
I get the following error.
Error: Unrecognized argument
'"-preSync:runCommand='F:\Projects\Unleashed\Release_Scripts\WindowsServices\deployTopShelfServicePreCommands.cmd
Unleashed.Maintenance.JobScheduler
C:\MyCompany\Services\MyCompany.Maintenance.JobScheduler',waitInterval=30000"'.
All arguments must begin with "-".
Note that after the PreSyncCommand, is params that I want to pass to the CMD file (For it to know where to uninstall the existing service from etc.
I've ran that params via EchoArgs.exe, and the args are fine.
If it matters (It might), I'm running the powershell script from TeamCity.
I've found the issue. As it turns out, it isn't powershell with the issue, but MSDeploy. MSDeploy as far as I can see does not allow you to pass batch files with parameters. Removing the parameters works fine (But then you need to hardcode them in your batch file, or work out some other way of generating the bat files on the fly).

None of my scripts run using PowerGUI, but they work directly from PowerShell

I just installed the latest version of PowerGUI (3.6.0.21).
When I try to run any script from inside PowerGUI I get the error message 'The file C:\Sandbox\MyPowerShell.ps1 cannot be loaded. The file C:\Sandbox\MyPowerShell.ps1 is not digitally signed.
I have googled all over for something simple to get around this, but no luck. What do I need to do to get this going?
Also, if I run the script commands from PowerShell directly they work.
AllSigned will not let you run an unsigned script. If you can't change the execution policy then import it as a module.
Save the script as a .psm1 and use Import-Module. It will bypass scripting policy because it's being loaded/run as a module.

copy command syntax error in Windows XP

Basically I am just trying to create a batch file to copy one file from one location to another location in Windows XP like the code below but failed. May I know why?
copy C:/Directory_A/the_file D:/Directory_B
When I execute the batch file I see this in the output:
The syntax of the command is incorrect.
Try using backslashes
copy C:\Directory_A\the_file D:\Directory_B

MSBuild fails when run via Powershell

I have an MSBuild script that I want to call from a PowerShell script as part of a deployment process. If I call the build script via a bat file all works well. If I do the exact same thing in PowerShell I get CS1668 error looking for wierd and wonderful paths that dont exist on my machine.
I know I am getting into the MSBuild script as these errors are occuring from within the MSBuild script targets (logging output is showing this).
The bat file and the PowerShell script reside in the same place, right next to the build script.
Errors:
error CS1668 : Warning as error :
Invalid search path 'C:\Program
Files\Microsoft Visual Studio
8\VC\AtlMfc\Lib' specified in 'LIB
environment variable' -- 'The system
cannot find the path specified. '
error CS1668 : Warning as error :
Invalid search path 'C:\Program
Files\Microsoft Visual Studio
8\VC\PlatformSDK\Lib' specified in
'LIB environment variable'-- 'The
system cannot find the path specified.
'
I have checked and neiter of these paths do NOT exist on my machine.
Why would running from PowerShell change what paths MSBuild look for?
Thanks in advance
RhysC
EDIT- adding in code: NB the name of the MSBuild script is AutomatedDebug.build
POWERSHELL SCRIPT:
#Begining of script
$CurrentPath = Split-Path (Split-Path $myinvocation.mycommand.path )
#Assign the Build script paths. 1 is for building and testsing, 1 is for deployment (to keep things clean)
$MSBuildScriptBuildAndTestPath = $CurrentPath + "\Tools\AutomatedDebug.build"
$MSBuildScriptDeployPath = $CurrentPath + "\Tools\Deploy.build"
#Run the automated build with tests
Write-Host "*** Run the automated build with tests ***"
C:\Windows\Microsoft.NET\Framework\v3.5\MSbuild.exe $MSBuildScriptBuildAndTestPath "/t:AllTests" "/l:FileLogger,Microsoft.Build.Engine;logfile=AllTests.log"
if($LastExitCode -ne 0)
{
throw "AllTests failed"
}
Write-Host "*** FINISHED: Run the automated build with tests ***"
Bat File
#C:\Windows\Microsoft.NET\Framework\v3.5\MSbuild.exe AutomatedDebug.build /t:AllTests /l:FileLogger,Microsoft.Build.Engine;logfile="AllTests.log"
#pause
enter code here
Ok, what is actually happening is that I have dowloaded the Powershell Community Extensions (http://pscx.codeplex.com) many moons ago and there is a Environment.VisualStudio2005.ps1 file in there that adds EnvVars that dont exist. This is (I assume) becuase i dont use VS2005. I have commmented this out and all is well. I have tried to look for the 2008 equivilent but dint have too much luck. To be honest i dont use powershell to its full potential so i doubt i even need the PSCX on my machine anyway.
Thanks guys for your help.
It is most likely due to how you are passing parameters into the MSBuild script. There are some key parameter parsing differences between CMD and PowerShell and by using a batch file, you are implicitly using CMD's parameter parsing engine to hand off the parameters to MSBuild. If you post the command line you're using, one of the PowerShell gurus here can probably help debug where the parameters are getting confused.
I am wondering, basically you get "Warning as error" here. You can either try turning off treating warnings as errors (I mean, having a lib path which doesn't exist doesn't sound that bad to me) or you'll let your scripts print out the respective environment variables (using echo %LIB% and $Env:LIB respectively) from the scripts and look for differences.
However, since the envvars for VS aren't set globally by default (that's why there are the three Visual Studio command prompts) you have to set all variables somewhere. If you're doing this within the scripts you may have a typo somewhere?