PsExec not able to logon to remote machine - psexec

I have a bunch of machines to be joined to a domain. They have same name and hence I am using a VBScript to change the host name of these machines (Win7) and then add them to the domain.
The script is present on all the remote target machines and we are trying to run it thorugh psexec from a different machine.
The problem is that PsExec is not able to logon to the target machines. It gives "Access Denied" error. I am using the credentials as... -u "target machine name"\"administrator name" -p
Something like this...
PsExec.exe \%%a -u "target machine"\"administartor name" -p XXXXXXXXX -s cmd "/C cscript.exe \path\to\script.vbs \reboot"
Please help me understand the issue here. I have tested that PsExec works when the remote target machine is on the same domain. Whats the difference between a workgoup and domain.

folks, i found the answer...
PsExec needs the local administrator account on windows to be enabled. Recent Windows(following linux) has made this account default set to disabled(the logic is the same as for 'sudo' in linux: security). Enable this account by the following command(run command prompt as administrator)...
net user administrator /enable:yes

Related

PsExec -i parameter works only with console

I am using PsExec to run a process on a remote computer but I want also to use the -i parameter in order the process interact with the computer desktop.
For example:
PsExec.exe \\computer1 -i -h powershell.exe -noexit -command hostname
When I RDP to the machine, I cannot see the "GUI" if the powershell, but I do see a new PowerShell process run under processes.
But if I am using the console feature in my virtualization environment (as this is a VM), I can see the PowerShell process pops up.
Tried to search online a "Console" like feature when using RDP to a machine but it seems like the /console argument has been deprecated...
What else can I try?
I found the solution thanks to hawaii:
I just need to add the session id after the i parameter.

PsExec64.exe to encrypt password and sore is throwing error

I am new to power shell scripting. I have used below piece to encrypt and store password:
$password = "TestingWithSamplePassword"
$salt = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 10 | % {[char]$_})
$encryptPasswordFile = "& script_path\PsExec64.exe -accepteula -nobanner -s powershell -Command {$password|ConvertTo-SecureString -Force -AsPlainText|ConvertFrom-SecureString}"
Invoke-Expression -Command:$encryptPasswordFile
It fails with below error:
PsExec executes a program on a remote system, where remotely executed console
applications execute interactively.
Usage: psexec [\\computer[,computer2[,...] | #file]][-u user [-p psswd][-n s][-r servicename][-h][-l][-s|-e][-x][-i [se
ssion]][-c [-f|-v]][-w directory][-d][-][-a n,n,...] cmd [arguments]
-a Separate processors on which the application can run with
commas where 1 is the lowest numbered CPU. For example,
to run the application on CPU 2 and CPU 4, enter:
"-a 2,4"
-c Copy the specified program to the remote system for
execution. If you omit this option the application
must be in the system path on the remote system.
-d Don't wait for process to terminate (non-interactive).
-e Does not load the specified account's profile.
-f Copy the specified program even if the file already
exists on the remote system.
-i Run the program so that it interacts with the desktop of the
specified session on the remote system. If no session is
specified the process runs in the console session.
-h If the target system is Vista or higher, has the process
run with the account's elevated token, if available.
-l Run process as limited user (strips the Administrators group
and allows only privileges assigned to the Users group).
On Windows Vista the process runs with Low Integrity.
-n Specifies timeout in seconds connecting to remote computers.
-p Specifies optional password for user name. If you omit this
you will be prompted to enter a hidden password.
-r Specifies the name of the remote service to create or interact.
with.
-s Run the remote process in the System account.
-u Specifies optional user name for login to remote
computer.
-v Copy the specified file only if it has a higher version number
or is newer on than the one on the remote system.
-w Set the working directory of the process (relative to
remote computer).
-x Display the UI on the Winlogon secure desktop (local system
only).
-arm Specifies the remote computer is of ARM architecture.
-priority Specifies -low, -belownormal, -abovenormal, -high or
-realtime to run the process at a different priority. Use
-background to run at low memory and I/O priority on Vista.
computer Direct PsExec to run the application on the remote
computer or computers specified. If you omit the computer
name PsExec runs the application on the local system,
and if you specify a wildcard (\\*), PsExec runs the
command on all computers in the current domain.
#file PsExec will execute the command on each of the computers listed
in the file.
cmd Name of application to execute.
arguments Arguments to pass (note that file paths must be
absolute paths on the target system).
-accepteula This flag suppresses the display of the license dialog.
-nobanner Do not display the startup banner and copyright message.
You can enclose applications that have spaces in their name with
quotation marks e.g. psexec \\marklap "c:\long name app.exe".
Input is only passed to the remote system when you press the enter
key, and typing Ctrl-C terminates the remote process.
If you omit a user name the process will run in the context of your
account on the remote system, but will not have access to network
resources (because it is impersonating). Specify a valid user name
in the Domain\User syntax if the remote process requires access
to network resources or to run in a different account. Note that
the password and command is encrypted in transit to the remote system.
Error codes returned by PsExec are specific to the applications you
execute, not PsExec.
Help would be highly appreciated..
Try this:
$encryptPasswordFile = "& 'script_path\PsExec64.exe -accepteula -nobanner -s powershell -Command {$password|ConvertTo-SecureString -Force -AsPlainText|ConvertFrom-SecureString}'"

Starting Service on remote server failed

I encounter strange behavior when trying to remotely start a service.
on Server A i'm running this line (it's part of bigger script named RunRemoteService.ps1):
Invoke-Command -ComputerName $B_comp -ScriptBlock {Powershell.exe -File "run_service.ps1"} -Credential $cred
And the script run_service.ps1 contains the following line (it's also part of bigger script):
$my_service_name.Start()
Now here's the strange thing, If I run RunRemoteService.ps1 when I have an open remote connection (mstsc) to server B then the script works perfectly and the required service on B is really starting.
However, if I run RunRemoteService.ps1 when there is no mstsc connection with server B then the script failed (service doesn't start).
Why is this happening and how can it be resolved?
EDIT: I explored this issue a bit more and found out that this occurs only when trying to run my specific service.
that means that my service must run from a session of already logged on user (that is why it's working if I mstsc to the server before).
So I guess my new question is - is there a way I can login to remote machine from powershell?
Thanks.
If you cannot use Credential delegation as suggested by #EBGreen. Try using psexec.exe for calling the script instead of PowerShell remoting.
psexec \\server "cmd /c powershell.exe -f c:\script.ps1"
Get psexec from sysinternals.com
Ok, so my question had evolved and modified on the fly so this solution is to the latest issue I had which is - I couldn't remotely start my service if no user is logged on to remote machine.
The solution is a workaround:
I configured auto-login (using sysinternals auto-login tool) on remote server.
I used Restart-Computer cmdlet at the beginning of the test.
Now after the restart is complete and ps-session is restored, user is logged in automatically to server and I can remotely start my service.
Thanks.

Using 'net use' through PowerShell exhibits different behaviour when done through cmd on a Windows Server 2012 instance

I have a cloud service with the following line of code in startup.cmd:
net use n: \\<storage-account>.file.core.windows.net\scorm /u:<storage-account> <storage-password>
This successfully creates the mapped drive to point to the Azure File Services share, but it shows in Windows explorer as a disconnected drive and any attempt to remove it using the 'Disconnect' option results in a "This network connection does not exist" although if I double click the folder I am successfully able to access the files.
If I run the same command through a cmd prompt the drive shows as connected with the name of the share and the path displayed. Do I need to do anything different in the PowerShell startup command to render the same results as the cmd line prompt?
The "net use" command only connects to the share in the context you are running. So you will have to run the "net use" in the same context your role will run.
For web roles this will be "NT AUTHORITY\NETWORK SERVICE". To run "net use" in that context, you need a tool like psexec.exe, which you can download from Windows Sysinternals.
Place psexec.exe into your role's bin directory, and set up an elevated startup script with this command:
psexec -accepteula -u "NT AUTHORITY\NETWORK SERVICE" net use n: \\<storage-account>.file.core.windows.net\test /u:<storage-account> <storage-password>
Drives are mapped to your user token, and administrators have two tokens. Limited and elevated. Make sure you are using consistent tokens. I.e. if mapped while Run As Aministrator then only programs running elevated can access that mapping.

psexec double backslash error

I am trying to run the following command in power shell but it keeps giving me error at the double back slash character.. what do i do!! I saw other forums and this yntax works fine for them!
$combined="C:\tools\PsExec.exe \\computer cmd.exe"
PS C:\Users\Desktop\initialutility\initutil_v2> Invoke-Expression $combined
At :line:1 char:20
+ C:\tools\PsExec.exe <<<< \\computer cmd.exe
I substituted \computer with \x.x.x.x (i.e Ip address)..still no use..
Please help!
I believe your problem lies elsewhere as double slashes work fine e.g.:
PS> $command = "c:\bin\psexec.exe \\genericpc1 hostname.exe"
PS> iex $command
PsExec v1.98 - Execute processes remotely
Copyright (C) 2001-2010 Mark Russinovich
Sysinternals - www.sysinternals.com
GENERICPC1
hostname.exe exited on genericpc1 with error code 0.
I would try running psexec.exe outside the context of Invoke-Expression and get that working first. Another issue with using psexec is that it uses your credentials if you don't specify any credentials. That means, your credentials need to work on the remote system.
Other requirements, from an article on PsExec are:
PsExec's ability to run processes remotely requires that both the
local and remote computers have file and print sharing (i.e., the
Workstation and Server services) enabled and that the default Admin$
share (a hidden share that maps to the \windows directory) is defined
on the remote system.
... impersonates the account from which you run PsExec on the local
system. Impersonation is somewhat restricted from the perspective of
security—the remote process doesn't have access to any network
resources, even those that your account typically would be able to
access. If the account in which you're running doesn't have local
administrative privileges on the remote system, the process you want
to run requires access to network resources, or you want to run a
process in a different account, then use PsExec's -u switch to provide
an alternative account name.
share (a hidden share that maps to the \windows directory) is defined
on the remote system.