I have two remote PC's that are being used to execute some powershell scripts, one is windows 7 and one is windows 10. Occasionally (if a reboot needs to happen) the scripts require admin privilege. On the windows 7 remote PC it always runs powershell as admin so it works fine. However on the remote windows 10 PC it does not, stopping the program from executing. What I need to know is how to get the remote windows 10 PC to run powershell as admin by default, anytime a powershell script is run.
I know this is possible because on a separate PC I've used powershell always opens in admin, but I've searched through the settings and can't figure out why.
Any help would be appreciated,
Thanks
If you fully disable UAC by changing the registry:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
Value: "EnableLUA"
to 0, it will default run all programs (including powershell) as admin
Related
I have a host machine with Hyper-V enabled, and I have a Hyper-V guest running on this machine. Becauze I can't drag&drop files to the VM, I wrote a script to do this for me, which is integrated in TotalCommander, and which uses Copy-VMFile.
My problem is that the PS script works only if I run it as admin, otherwise I get the error "You do not have the required permission to complete this task."
Why do I need admin to copy from the host machine to the guest OS? And is there a way, some policy which would allow me to circumvent this? It is annoying to enter a password every time I want to copy some files.
I'm trying to get Remote-SSH working with ssh-agent, from Windows 7 desktop to CentOs 7 server.
I'm using ssh, ssh-add and ssh-agent from the Git for windows package. From the cmd prompt, this is all working fine, I can "ssh-add -l" and see the keys, and I can run "ssh " and it runs with no problems and without asking for password:
C:\Users\gnb>"c:\Program Files\Git\usr\bin\ssh-add.exe" -l
4096 SHA256:zg2IR6OlPwCGP8SzcbriXIQjth5zuDc9rbO6uaNPmcU gnb#VDI028-MEL (RSA)
C:\Users\gnb>ssh vdi ls
Desktop
tsclient
wkspace
C:\Users\gnb>
From within VS-Code, I can't get this to work. Running the exact same ssh-add command from within the VS-Code Terminal does not seem to find the agent:
C:\Users\gnb>"c:\Program Files\Git\usr\bin\ssh-add.exe" -l
Could not open a connection to your authentication agent.
The actual remote functionality in VS-Code more or less works, but keeps stopping to ask for passwords.
What's missing here? Why can the vs-code environment not connect to the ssh-agent?
OK, I've had a few more hours playing around with this and I think I understand what's going on.
It only works from cmd if it is the same cmd window that was used to start the agent. Opening a new cmd window then ssh gets the same msg as starting vs-code from the menu - can't find the agent. It appears that the start-ssh-agent script that comes with git/ssh on Win7 is setting some environment variables or some such that the ssh client needs. This does make sense, Unix ssh-agent acts the same way, but I'm clearly not used to thinking about windows apps in those terms.
It also seems the start-ssg-agent script will set the environment variables to point to an existing agent if one is running, else will create a new agent. So a 2 line batch file
start-ssh-agent
code
will reliably start up VS Code with the ssh-agent. If you name the identity file in the ssh config, vs-code will add they key to the agent when required. Otherwise you need to manually add the key to the agent, or fall back to entering the password all the time.
Suspect the better solution is to be on Win10 and use ssh-agent as a service, which should mean VS-code should find the agent when run from a menu. But I can't test that.
I have a script to assign static IP address to HyperV VM's whenever it found 169.x.x.x series IP,and the script start work when we logged in to the machine as Administrator.
Is it possible to run the script while machine booting ? So that, we don't need to log in to the VM's to run the script ?
You don't give us any information about your deployment process. But you could essentially use the SetupComplete.cmd. Run your PowerShell script from there.
See Add a Custom Script to Windows Setup.
I'm using PuTTY to connect to an SSH server running on Windoes 7.
When I issue powershell in PuTTY terminal does it mean that the powershell command window opens on the remote machine?
If so how does the output from remotely running powershell window gets routed to PuTTY client?
Sorry if this is lame question but it's not so obvious to me.
While the PowerShell is executed on the remote machine, no window opens on the server.
powershell.exe is a console application. Console applications have a standard IO (input and output). If you run a Windows console application locally, Windows GUI creates a console window and binds the application IO to the window. While if you run a console application via an SSH server, the SSH server binds the application IO to the SSH shell session. So anything that the PowerShell prints, gets routed to the SSH shell session output, which ultimately renders in your local SSH client window (PuTTY).
In other words, a local PowerShell window is rendered by Windows GUI (the system that executes the PowerShell), not by the PowerShell process itself (contrary to windows of GUI applications). Another system, like the SSH server, can choose a completely different "rendering" of the IO, like routing the IO to the SSH shell session.
It's the same process like, if you use ls command on a *nix server. The ls is also a console application. (Afaik, all *nix applications are actually console applications, what is not true on Windows.)
As the title describes I need to run a command on a remote server and I do not have access to remote desktop! I head that this should be possible using Powershell, but I can't find any good tutorials on this.
Recommendations?
The easiest way is to use psexec.exe (Part of Microsoft Sysinternals).
You can also use powershell.
I wrote a blogpost about these two alternatives a few days ago:
http://blog.degree.no/2012/03/executing-commands-and-programs-on-a-remote-machine-using-powershell/
When using PSEXEC or PowerShell remoting you can execute a command on a remote machine, but it is not interactive with any currently logged on user. Using PowerShell requires 2.0 to be installed on your machine and remotely AND remoting must be enabled AND you must have admin rights on the remote computer.