I'm using Windows Jenkins and installed the windows powershell plugin. from Jenkins I'm trying to connect to Linux instance and execute some commands in linux server.
> New-SshSession -ComputerName 10.0.0.xx -Username username-Password
> jenkins#123 Invoke-SshCommand -ComputerName 10.0.0.xx -Command "cd
> docker_CIServiceApp ; unzip prod.zip -d prod/"
But getting the error message from jenkins job as
New-SshSession : The term 'New-SshSession' is not recognized as the
name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
The same command works in Windows Powershell terminal. What will be the issue?
The reason for it might be that the Jenkins was started before SSH.NET plugin was installed. It modifies the environment variable and it requires process restart. Try restarting Jenkins process. Alternatively, it might be that the module is not loaded, try loading it first: Import-Module SSH-Sessions.
So, apparently you have installed a package in Visual Studio solution. Visual studio takes care of package download for you (restoration). It gets downloaded into packages folder under your solution. When you have no Visual Studio, like when using Jenkins and MS Build directly, you have to download package manually - get nuget.exe and run nuget restore your_solution.sln, this will then download the package under "\packages". Now you will have to import module, using the "\packages" path, probably.
your error indicates tha the module isn't installed:
PS /home/thufir/powershell>
PS /home/thufir/powershell> Install-Module -Name SSHSessions
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this
repository, change its InstallationPolicy value by running the Set-PSRepository
cmdlet. Are you sure you want to install the modules from 'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help
(default is "N"):Yes
PS /home/thufir/powershell>
Related
I have downloaded a custom build agent for an Azure Devops release pipeline. I am trying to execute a sed statement within the release pipeline, but I am getting an error that the term sed is not recognized as the name of a cmdlet, function, script file, or operable program. Any advice on how I can get sed installed in a custom build agent would be appreciated.
As per the error message, you are running sed in powershell task.
Please change to use Bash task as it's a unix based command.
Since you're using self-hosted agent, please make sure you have installed mingw(you can install git for windows(git bash) which include mingw) on windows machine, run sed --version locally, make sure it can run successfully. Follow link to add "C:\Program Files\Git\bin" to the Path of Environment Variables, then restart the agent service. You can invoke bash in pipeline now.
My local command:
My pipeline with bash task:
I know nothing of PowerShell, but I wanted to install this: https://www.powershellgallery.com/packages/lolcat/
So, I start PowerShell as administrator, and:
PS C:\WINDOWS\system32> Install-Module -Name lolcat NuGet provider is required to continue
PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet
provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or
'C:\Users\Me\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running
'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import
the NuGet provider now?
[Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): y
Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its
InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from
'PSGallery'?
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): y
PS C:\WINDOWS\system32> lolcat
Usage: lolcat [OPTION]... [FILE1[, FILE2[, ...]]]
...
Nice, it works. So first I find where is the newly installed script:
PS C:\WINDOWS\system32> (Get-Module lolcat).Path
C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1
Ok, so now I want to try calling this from cmd.exe:
C:\Users>PowerShell.exe -File "C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1"
Processing -File 'C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1' failed because the file does not have a '.ps1' extension. Specify a valid Windows PowerShell script file name, and then try again.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
Nope, does not work.
Is it possible to call this PowerShell script from cmd.exe - and if so, how?
The error is due to the fact that the -File parameter from the powershell.exe excepts a .ps1 file.
If you want to run C:\Program Files\WindowsPowerShell\Modules\lolcat\1.0.7\lolcat.psm1 from cmd, make a .ps1 script where you can write something like
Import-Module lolcat
# now you have all the functions from the lolcat module loaded into this PowerShell session
# do stuff
And then call this script from cmd.
The difference between .ps1 and .psm1 is explained here.
Eh, turned out to be less complicated then I thought - since it is a "module", just use the module name:
C:\Users>PowerShell.exe lolcat
Usage: lolcat [OPTION]... [FILE1[, FILE2[, ...]]]
...
I want to install appx Package with $Add-AppxPackage, but I need to install the app on my 2nd HDD, so how to change installation path in PowerShell $Add-AppxPackage?
You couldn't change the install location during the add-appxpackage process, there is no optional parameter for changing the install location in the Add-AppxPackage. You could see the same opinion in the thread:Question on "Add-AppxPackage" powershell command
However, you could try to change the app's install location after the app is installed.The steps for the Windows 10:Setting-->Apps-->Apps&features-->select your app-->Move-->Choose your 2nd Hdd.
I just copied the files where i wanted them to be (not program files though, doesn't work) set-location "THE FILEPATH YOU TRANSFERRED TO"
And then run the Add-AppPackage command once you're in the directory
So I'm trying to find a command to uninstall apache from windows that I have installed earlier with an NSIS script.
Basically apache is part of a package of aplications we use for our program, and when uninstalling our program we uninstall them all. Already working for postgres, java and ruby, but I'm not finding any command for apache.
I tried the wmic command, but it required user to confirm the action. There isn't any httpd uninstall command?
httpd -k uninstall
simply removes the service.
Thanks
sc delete Apache2.4
Remove service in windows
On Windows 8.1 I had to run cmd.exe as administrator (even though I was logged in as admin). Otherwise I got an error when trying to execute: httpd.exe -k uninstall
Error:
C:\Program Files\Apache\bin>(OS 5)Access is denied. : AH00373: Apache2.4: OpenS
ervice failed
I've had this sort of problem.....
The solve: cmd / powershell run as ADMINISTRATOR! I always forget.
Notice: In powershell, you need to put .\ for example:
.\httpd -k shutdown .\httpd -k stop .\httpd -k uninstall
Result: Removing the apache2.4 service The Apache2.4 service has been removed successfully.
If Apache was installed using NSIS installer it should have left an uninstaller. You should search inside Apache installation directory for executable named unistaller.exe or something like that. NSIS uninstallers support /S flag by default for silent uninstall. So you can run something like "C:\Program Files\<Apache installation dir here>\uninstaller.exe" /S
From NSIS documentation:
3.2.1 Common Options
/NCRC disables the CRC check, unless CRCCheck force was used in the
script. /S runs the installer or uninstaller silently. See section
4.12 for more information. /D sets the default installation directory ($INSTDIR), overriding InstallDir and InstallDirRegKey. It must be the
last parameter used in the command line and must not contain any
quotes, even if the path contains spaces. Only absolute paths are
supported.
Try this :
sc delete Apache2.4
or try this :
C:\Apache24\bin>httpd -k uninstall
hope this will be helpful
I have installed Nagios monitoring tool in linux whose service is running successfully as expected.
Now as per NSClient documentation, the windows part is not getting installed.
The required steps are:
(a) Copy pNSClient.exe, pdh.dll, psapi.dll and counters.defs in any directory on the machine you want to monitor. ie. (c:\nsclient).
(b) Open a dos prompt in the installation directory
(c) Run the following command : >pNSClient.exe /install
(d) Type 'net start nsclient' on the command line or start the service 'Nagios Agent' in the services applet of the control panel.
The installation will create an entry for the service in the registry and create a new key to store parameters. The created key is the following:
HKEY_LOCAL_MACHINE\SOFTWARE\NSClient
The issue is with the installation as per the first step, and the 'net start nsclient' command is not executing on command prompt, its showing service name invalid
Any help regarding this ? M installing this on windows 7.
Only the windows installation part of NSClient is remaining yet the linux part is properly installed along with the 'check_nt' plugin.
Thanks in advance !!
NSClient is antiquated and deprecated. You should be using NSClient++ (AKA nscp), which has an actual installer, along with excellent documentation.
Alternatively, if you are dealing with more than a few dozen Windows hosts, and are using Active Directory, you might want to consider Nagios-WSC. Whether or not it will suit your needs depends on what sort of checks you are hoping to do, though.
That documentation might be out of date. Try using the following doc to install NSClient++. The doc is for Nagios XI, but the agent instructions should be the same.
http://assets.nagios.com/downloads/nagiosxi/docs/Installing_The_XI_Windows_Agent.pdf
Otherwise, you could also try:
net start nsclient++
just an advice - forget about manual installs )
install choco
iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
restart powershell session and
install nsclient++
choco install nscp