Trying to remove alias when running Powershell with NoProfile parameter doesn't work - powershell

I am trying to remove the alias for 'echo -> Write-Output' from Powershell using Remove-Item alias:echo when running command in 'Powershell -NoProfile' but it does not work, it still references the Write-Output alias. I am trying to run it in GitLab CI and GitLab runs all powershell commands using the 'NoProfile' parameter.

Related

how to just trigger a powershell script from azure pipeline without waiting for result of script

I have been tasked to automate test cases using azure pipelines for two applications.
(one is using allure and other is maven).
pipeline uses "PowerShellOnTargetMachines" task to remote into azure windows vm and executes a powershell script containing the test case commands.
since I am using Microsoft hosted agent and these tests run for more than 2 hrs pipeline fails with time limit 60mins.
so I used start-process in the pipeline which will trigger the powershell script in vm as background process and return. no waiting for pipeline. But script is only partially successful doesn't run entire commands.
and for the other application which uses maven all I have to do is run this single command "mvn clean install" which runs test cases and generates reports. running remotely from pipeline is not generating reports properly.
pipeline code:
- task: PowerShellOnTargetMachines#3
inputs:
Machines: '$(machineurl)'
UserName: '$(username)'
UserPassword: '$(password)'
InlineScript: |
cd <path>
start-process powershell.exe -WindowStyle Hidden -ArgumentList ". .\allure-report-html.ps1"
allure-report-html.ps1 script contains:
cd <proj-path>
behave -f allure_behave.formatter:AllureFormatter -o testcasejson "features/main.feature" "features/announcements.feature"
allure generate testcasejson
allure-combine .\allure-report
$sdate = (Get-Date -format "yyyy_MM_dd hh.mm")
$report_path = '<report_path>'
$project_path = '<project_path>'
Compress-Archive -Path $project_path\$sdate -DestinationPath $report_path\$sdate.zip -Force
this works completely fine inside VM using same start-process command. but when running from pipeline I can only see "testcasejson" folder generated from behave command but I can't see "allure-report" folder which will be generated from allure commands.
I just need to trigger a PowerShell script in VM from pipeline without waiting for it to complete.
is there any other method to achieve this

Executing two commands one after another in the same powershell session

For context, I’m trying to activate a virtual environment, and then run my python script from within that venv, all in one powershell session. I’m doing this in a .bat file that I will later start as a service (The whole point of this is to run main.py in the venv as a windows service)
I tried this:
powershell -noexit -file C:\MyPythonProject\venv\Scripts\Activate.ps1; python C:\MyPythonProject\main.py
This doesn’t seem to work. Only the first command (to activate the venv) works. What am I doing wrong?
use & to chain commands:
powershell -noexit -file C:\MyPythonProject\venv\Scripts\Activate.ps1 & python C:\MyPythonProject\main.py
https://superuser.com/questions/1079403/how-to-run-multiple-commands-one-after-another-in-cmd/1079420

Jenkins to call powershell script but doesn't execute

Is there a way wherein Jenkins call a powershell script and just stops without waiting for an output? I don't want it to run under the context of jenkins. Jenkins would be used ONLY to pass the form parameters.
Reason : Jenkins doesn't work quite well with Internet explorer COM objects because script works fine when called directly or task scheduler but fails using Jenkins at few steps. Tried multiple work-around but failed.
So, the resolution is that I would call the script using Jenkins only so that it runs under the context of powershell only. Jenkins would be used ONLY to pass the form parameters.
Regards,
Rahul
powershell Start-Job command should work
powershell script: '''
Start-Job {
param($someArgument)
// set location as current directory
Set-Location $using:PWD
//start a command
PowerShell -NoProfile -ExecutionPolicy Bypass -Command .\myscript.ps1
} -Name "myJob1" -ArgumentList $someArgument
'''

How to execute powershell script from jenkins by passing parameters

I have a powershell script in my Github. i am trying to execute that via Jenkins. Here is a part of the script :-
param (
+ [string]$fileDir = "%WORKSPACE%\src\Project\***",
[string]$packagingDir = "%WORKSPACE%\src\packageTemp",
[string]$staticFilesToDeploy = "%WORKSPACE%\src\****"
)
Now i am using a simple batch execution within Jenkins Job to run this script. I am trying to run it as
powershell -noexit "& ""%WORKSPACE%\src\***.ps1"""
But when Jenkins actually executes this powershell script its unable to replace %workspace% within the script and fails as it cannot find that. How do i make jenkins to replace that within the script when it executes it actually
I was able to get this resolved by passing arguments for the powershell script through jenkins :-
powershell.exe -file "%WORKSPACE%\src\***.ps1" -fileDir "%WORKSPACE%\src\Project\***" -packagingDir "%WORKSPACE%\src\packageTemp" -staticFilesToDeploy "%WORKSPACE%\src\****"
This force sets the values for the params within the script at run time and at the same time can be issued via jenkins to be able to make use of its environment variables.

PowerShell: Starting the CLR Failed with HRESULT 8007000e

I'm getting the following error when running PowerShell scripts on a remote server:
Starting the CLR Failed with HRESULT 8007000e
This is basically how I'm running/calling the scripts:
On the local server I'm running a CMD script that calls a PowerShell script to create a remote session to a remote server. In the PowerShell script I also call a CMD script to run on the remote server like so:
$Script = [scriptblock]::create("cd $BuildPath | cmd.exe /c install.cmd $apptype")
The install.cmd script runs on the remote server and calls a PowerShell script that executes a series of tasks.
powershell ./Install.ps1 -BuildNum %BUILDNUM%
After the tasks are complete, the PowerShell script then calls another PowerShell script to run a separate series of tasks. This is when I hit the above error, when the second PowerShell script is called.
This is how the second PS1 script is called from the first PowerShell script:
powershell "& {. $BinToolsSrc\PostInstallValidation.ps1 -BuildNum $BuildNum -Test 'True'; Run-Validation -App $App -AppLoc $AppLoc -Env $Env:ENV -Site $Site -AppPool $AppPool -Config $Config -EnvConfig $EnvConfig -DllPath $DllPath}"
What usually causes the type of CLR error that I'm getting and how do I resolve it?
NOTE: I do not get this error when I run the install script locally on the remote server.
Thanks in advance!
UPDATE: Installing PowerShell 3 on the remote server seems to have solved the problem as it targets the .NET 4.0 runtime.
I too had the same problem because I have changed some path settings in my VScode unknowingly.
I have changed the settings to command prompt which works fine for me now...(This might not be the best solution though).screenshot