We would like to execute powershell scripts which are located at windows share drive eg: winvmx01\folder1\folder2\script.ps1 from linux machine.
We installed powershell in linux machine and running Invoke-Command -Computername winvmx01 -ScriptBlock { Get-ChildItem "C:\Program Files" }
but it cant able to find commands of powershell and posting an error /bin/bash: line 69: Invoke-Command: command not found.
when we tried to check version it is showing up fine
pwsh
PowerShell v6.0.4
Copyright (c) Microsoft Corporation. All rights reserved.
https://aka.ms/pscore6-docs
Type 'help' to get help.`
can someone please suggest how we can proceed. if not powershell is there any other client that we can use to execute a script in windows shared machine.
Thanks!
Related
I've been working on trying to run a Powershell script on the network using PSExec, but every time I run it, I get this message:
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
Couldn't access [COMPUTER]:
The filename, directory name, or volume label syntax is incorrect.
C:\PSTools> psexec \\[COMPUTER] /s cmd /c %SystemRoot%\system32\WindowsPowerShell\
v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\apps\test.ps1
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
The argument 'c:\apps\test.ps1' to the -File parameter does not exist. Provide
the path to an existing '.ps1' file as an argument to the -File parameter.
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
cmd exited on [COMPUTER] with error code -196608.
The goal of the script is to traverse domain-connected laptops and save a specific list of directories to a file on my computer. That script is as follows:
powershell.exe -command "& {& get-childitem 'c:\users\*\appdata\local\google\chrome\user*data\default\extensions\*'}" > \\[MY_COMPUTER]\C$\users\[USERNAME]\desktop\Chrome_Extensions.txt
I am calling this script with this command:
psexec \\[COMPUTER] /s cmd /c %SystemRoot%\system32\WindowsPowerShell\
v1.0\powershell.exe -ExecutionPolicy Bypass -file c:\apps\test.ps1
When I run the script without psexec \\[COMPUTER] /s , it runs fine and saves the correct information about the computer I'm running it on, then sends the information to my computer's desktop. But running it with the aforementioned line causes the error above, and I can't target machines on the network. So, what about the PSExec command causes this to error out, as it doesn't seem like there's really a lot to it? Perhaps I'm misunderstanding, and assuming that PSExec should run the same as PowerShell, which very well might not be the case. I guess I'm just a little lost on how to use it, and any assistance would be greatly appreciated! Thank you!
With help from #Briantist, I've been able to run the command Enable-PSRemoting on the target computer, then run the script with invoke-command -computername [COMPUTER] -filepath c:\apps\test.ps1
Using PSExec was just too messy, so I'm glad this was able to work another way. Now to figure out how to enable remoting on all computers on the domain without connecting to all of them individually and doing it manually...
I have a VBScript file that I would like to run on a remote machine using invoke:
Invoke-Command -ScriptBlock { cscript.exe "C:\test.vbs" } -Computer Machine1
When I execute this command, nothing happens. Neither on the remote machine nor in the shell window on my local machine; the only lines that appear in my local shell window after executing are:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
But it stays like this and I am not able to do anything anymore with the shell. I also dont get any error msg. The VBScript itself is quite small and takes just a few seconds to run. Also I did try and run the VBScript on the remote host directly (in remote desktop) and it is working.
Any clue where I could get some details on why the remote call doesn't do anything?
I'm trying to execute a Powershell script which contains Sharepoint commands as part of my Jenkins job.
Seemingly, the Sharepoint snapin is only available to 64bit Powershell sessions. A 32bit session does not show the Sharepoint snapin.
64bit
PS C:\Users\user> Get-PSSnapin -Registered
Name : Microsoft.SharePoint.PowerShell
PSVersion : 1.0
Description : Register all administration Cmdlets for Microsoft SharePoint Server
Most suggestions to run a 64bit Powershell are to run from the following path. Even if I test this from a 32bit command prompt, I still get a 32bit Powershell instance
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
How can I execute 64bit (and therefore Sharepoint) Powershell commands via Jenkins?
Installing the 64bit JRE and starting Jenkins with that (edit jenkins.xml) resolved the issue.
Running powershell v2 with exchange management console 2007 installed.
a powershell prompt shows the registered snapings:
PS P:\> get-pssnapin -registered | fl name
Name : Microsoft.Exchange.Management.PowerShell.Admin
Name : Microsoft.Exchange.Management.Powershell.Support
I can run exchange related commands from a powershell prompt, however, powershell studio 2012 doesnt seem to recognize the addin. In my _load method, I have
Add-PSSnapin Microsoft.Exchange.Management.Powershell.admin
But get this when I run the script:
ERROR: Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2.
Powershell studio is the trial version and running v2 as well.
Maybe some snappins do not load with the trial?
You problem may come from the fact that PrimalScript 2012 and PowerShell Studio 2012 are 32 bit executables.
Have you got the two modes allowed in PowerShell Studio 2012 ?
I'm trying to install a msi file on a remote server using powershell.
Server 1 is my build server and server 2 is my application server.
When the build server finishes a buil, I want to trigger a powershell script to install the latest version to my application server.
I'm using the following command to create a session and execute the installation:
# Create session to Application Server
$Session = New-PSSession -Name <ApplicationServer> -ComputerName <ApplicationServer> -Auth CredSSP -cred OURDOMAIN\MyUser
# Prepare expression and create script block
$Script = "Invoke-Expression 'msiexec /i <InstallerFile> /qn /L*v C:\Temp\install_fail.log'"
$ScriptBlock = [Scriptblock]::Create($Script)
# Execute in the session
Invoke-Command -ScriptBlock $ScriptBlock -Session $Session
# Clean up the session
Remove-PSSession $Session
The log has the following error (see attachment install_fail.log for full log)
MSI (s) (C4:1C) [17:08:05:333]: Note: 1: 1708
MSI (s) (C4:1C) [17:08:05:333]: Product: WindowsService1 -- Installation failed.
MSI (s) (C4:1C) [17:08:05:335]: Windows Installer installed the product. Product Name: WindowsService1. Product Version: 8.0.0.0. Product Language: 1033. Manufacturer: MyCompany. Installation success or error status: 1603.
When I start a session on the powershell command promt and execute the installation the installation succeeds (see attachment install_success.log for full log):
ENTER-PSSession -ComputerName
Invoke-Expression 'msiexec /i /qn /L*v C:\Temp\install_success.log'
exit
When I print whoami in both cases it returns OURDOMAIN\MyUser.
Microsoft lists the following regarding the 1603: (http://support.microsoft.com/kb/834484)
The folder that you are trying to install the Windows Installer package to is encrypted.
The folder is not encrypted
The drive that contains the folder that you are trying to install the Windows Installer package to is accessed as a substitute drive.
The drive is a partition on the harddisk of the server
The SYSTEM account does not have Full Control permissions on the folder that you are trying to install the Windows Installer package to. You notice the error message because the Windows Installer service uses the SYSTEM account to install software.
The SYSTEM account has Full Control on the drive and all folders.
Please advise...
Have you tried using PSEXEC? or are you using powershell for a reason? I find that easier for remote installs than trying to go through powershell.
Just PSEXEC into the server CMD. Copy the files locally then run MSIExec to install.
I ended up writing a second PowerShell script that runs on the server watching a specific folder for new msi files. The script runs the first script that actually performs the installation tasks.