Hyper-V Start-VM stuck on "Connecting to..." - powershell

I want to start a VM from command line (running win server 2016),
but I found that the command Start-VM will cause the VM stuck on "Connecting to...",
the preview screen always shows black.
Until I opened the VM (double click on its name in Manager), it starts installing and works fine.
(It shows "connecting to" in the beginning.)
I can start the VM perfectly via Hyper-V Manager, but I can't start it using command line Start-VM. Why? How to solve this problem? Any help is appreciated!

Don't use CMD but Use powershell and type
Start-VM -Name "virtual machine name"

Related

How to restart docker for windows process in powershell?

I want to restart docker for windows (now known as Docker Desktop) in powershell.
I would like to do it with one command in PowerShell.
May I implement it?
When using Restart-Service *docker*:
Kill and restart the docker process:
$processes = Get-Process "*docker desktop*"
if ($processes.Count -gt 0)
{
$processes[0].Kill()
$processes[0].WaitForExit()
}
Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe"
In the if clause I check if any running docker process has been found. There should never be more than 1 instance of "Docker Desktop" running so you can then kill the first one in the list.
To restart you need to know the full path of the "Docker Desktop.exe" file on your computer.
You can user in powershell:
restart-service *docker*
Or int the Docker QuickStart Terminal:
docker-machine restart
On windows, open Docker desktop and click on the debug icon then restart. You can also consider "reset to factory defaults"
Similar to Sebastian L's comment above, but slightly cleaner & faster if you know whether you are currently running Linux or Windows containers.
If running Linux Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchLinuxEngine
If running Windows Containers
Stop-Service *docker*
Start-Service *docker*
&$Env:ProgramFiles\Docker\Docker\DockerCli.exe -SwitchWindowsEngine
-SwitchDaemon toggles from one to the other (Linux to Windows or Windows to Linux) which is why you have to do it twice.

Why process that terminated by script from PowerCli stuck in "suspended" mode

When I run a script trough PowerCLI after connecting to a VM, I get a strange behavior of some processes, I'm using the "Invoke-VMScript" command that is running an EXE file (compiled in .Net 4.5) that looks for running process and try to kill them.
For some reason some process doesn't get closed, and stuck in "Suspended" mode. When they stuck in this mode even if I tried to remove them from the task manager I get an error "The operation could not be complete, Access is denies."
I'm logged in with the Administrator user
The powershell script that I'm using is:
$executeCommand = "call D:\myCleaningProcess.exe $param1";
Invoke-VMScript -VM $vmName -GuestUser $vmUser -GuestPassword $vmPass -ScriptText $executeCommand
*When running manually the file "EXE" it's works as expected and the process get killed.
Anyone know why I get this strange behavior?
You need to use the -ScriptType Bat parameter when calling EXEs in this manner. See example 3 for reference: https://pubs.vmware.com/vsphere-55/index.jsp?topic=%2Fcom.vmware.powercli.cmdletref.doc%2FInvoke-VMScript.html

Royal TS PowerShell remote session does not work

I need to set up a PowerShell entry which connects with the PowerShell of the given server.
I haven't found anything helpful except of this instruction.
Instead of getting a PowerShell connection with the desired server I get a PowerShell connection of my local PC.
I also tried the same for cmd.exe and for Git Bash with no success.
I also tried to create tasks, but also with no success.
In all the cases I get the connection with my local PC.
My host system is: Windows 8.1 Enterprise 64 Bit
Royal TS: 3.2.9 (Build #60630)
What am I doing wrong?
Mostly solved :-)
By External Application Settings for PowerShell:
Command: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Arguments: -NoExit Enter-PSSession -computername my-remote-server
Working Directory: C:\Windows
-computername my-remote-server was missing, thatwhy it has not worked.
Unfortunatelly Working Directory does not work, I still land in C:\Users\j.sinitson\Documents.
Does someone know how to solve that?

Running a script off local machine to remote using Invoke-Command

Here is the command I am trying to run
Invoke-Command -ComputerName DOG-02 C:\Users\user\Documents\PowerShell\PowerShellmenuz.ps1
I want to be able to run the script PowerShellmenuz.ps1 on a remote machine. I am very close but am stuck at this point.
It is hard to tell where is the problem without error output, but probably you've missed first configuration step on remote machine. There things that should be done before executing scripts on remote machine.
Enabling PowerShell Remoting on the computer that you want access remotely. Open a PowerShell window as Administrator – right click the PowerShell shortcut and select "Run as Administrator". And execute the following command:
Enable-PSRemoting -Force - it will start service WinRM to allow incoming connections.

search event viewer server 03 and 08 r2

Is there a way to search the event viewer in Windows Server 2003 and Windows Server 2008 r2 for a particular printer name using powershell or another cmd or program?
From time to time I have to search event viewer to see who printed a particular print job and we usually know what printer they printed to, but it is very tedious to search manually.
If anyone is able to give an answer you will need to give the whole code since I am new to writing code. Sorry, but thank you for your help.
Edit:
I know you can export the list but what I am looking for is a way to parse the description of the events.
Program installs to complete this will be installed on a seperate computer as we try to keep our servers as clean as possible. Unless it is a standalone file that can be removed as soon as it is run all code will be run from a remote computer.
I kow about Log Parser but am unsure how to make it run on another computer, I'm sure I'm looking right past how to do it.
I will be running all programs from a Win 7 Pro 64 bit pc.
You can use the Get-EventLog cmdlet to obtain event log entries. In this example I connect to a remote computer named STUDIO running Server 2003 and search for Print events initiated by STUDIO\Administrator.
Get-EventLog -ComputerName studio -LogName System -Source Print -UserName "STUDIO\Administrator"
The printer name is contained in the message property so you can do a regular expression match.
Get-EventLog -ComputerName studio -LogName System -Source Print -UserName "STUDIO\Administrator" | where-object {$_.Message -match "PrinterName"}