воскресенье, 26 мая 2019 г.

Running 2 commands in a batch file

Suppose you have some conditions for running commands in CMD.

Firstly you want to run two commands one after another and then exit from a CMD window. I mean that both commands will continue to run, but a black window will disappear.
In addition, you want the second command is being executed 30 sec after the first command.
And another condition - the script should run automatically with turning on my laptop.

I really had this need. I wanted that my VPN client will run and connect me to my work and then (and only then) RDP client will connect me to the server at work.

How I made this done? Here is the little nice batch script.

:: START OF THE SCRIPT

start "" "C:\Users\User\Documents\RDP\FortiClient.LNK" /k
timeout 30
cmd /c start mstsc C:\Users\User\Documents\RDP\Vlad2016.rdp

EXIT /B 0
GOTO:EOF
taskkill /F /IM cmd.exe

:: END OF THE SCRIPT

In the end, I put the script to the startup folder on my Windows and from then both command are running automatically one after another.



пятница, 24 мая 2019 г.

Launch vSphere client automatically

To automatically launch VMware vSphere clients without having to enter user and password credentials, follow these steps:

It is possible, but there are two conditions for it:
1. You should be using old classical clients for vSphere 5.5 or 6.0.
New vSphere 6.5 and later only support web clients that can't do it because of today's security rules.
2. You shouldn't be afraid to save your passwords in clear text (that is not the best practice in most organizations).
If you are ok with all these conditions, I can show you the way.

First, we need to copy text from the original shortcut to a text file (because it is easier to edit it in the notepad).


This is the line:
"C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe"

Then you need to modify the batch file to include the vCenter server name or IP, username, and password as parameters:

"C:\Program Files (x86)\VMware\Infrastructure\Virtual Infrastructure Client\Launcher\VpxClient.exe" -s 10.0.0.1 -u Domain\Username -p password

After modifying the batch file to include the vCenter server name or IP, username, and password as parameters, you can paste the modified line back into the Target field of the original shortcut.


Now that you can launch the VMware vSphere client without entering credentials each time, there's even more to learn!

If you have multiple vSphere vCenters or want to run them all at the same time because you're searching for a specific computer and don't know which vCenter it's on, here's what you can do:

To launch multiple vSphere clients with different vCenter servers, you can create several shortcuts with the same format (you can clone the first and then modify the others as needed), and then create a batch file that will run all the shortcuts. Here's how:

Here is the format of the batch:
start "" /b ".\vSphere Client vCenter1.lnk"
start "" /b ".\vSphere Client vCenter2.lnk"
start "" /b ".\vSphere Client vCenter3.lnk"

All the shortcuts created in the previous step have a ".lnk" extension, so you need to include this extension in the batch file.
Note: As ".lnk" files are hidden in Windows by default, you may need to enable the option to show hidden files to see them. However, even then it may be difficult to view them.
Here's how:

Also, please note the following details regarding the batch file:

  • The use of double quotation marks around the paths to the shortcut files is necessary if the paths contain spaces.
  • The "/b" switch is used with the "start" command to run the applications without opening a new command prompt window.
  • The "./" sign in front of the ".lnk" file names specifies that the shortcut files are located in the same folder as the batch file. If your shortcut files are in a different folder, you will need to modify the file paths accordingly.

Additionally, it is possible to run different versions of the vSphere client (such as 5.5 and 6.0) at the same time, as long as they have been installed on the system.

To use the batch file, save it with a ".bat" extension and double-click it to run. It's a straightforward process that can save you time and effort when working with multiple vCenter servers.






четверг, 2 мая 2019 г.

How to launch Active Directory Users and Computers for a different domain/forest

If you are working with multiple domains that are not connected through full trust and need to run Active Directory Users and Computers or another MMC console file with credentials from a different domain, here is a solution for you.

To create a batch file, enter the following lines into a text editor:
runas /netonly /user:Domain\User "mmc dsa.msc /server=10.10.10.10"
runas /netonly /user:Domain\User "mmc dsa.msc /server=Domain.local"

Replace "Domain/User" and "IP" in the batch file with the appropriate values for your environment.

Please note that you will need to run the batch file as an administrator, although there is a way to avoid this which I will explain shortly. When you run the batch file, it will prompt you to enter your password in the Command Prompt window.


If you frequently use the batch file, you can use the following trick to avoid having to run it as an administrator every time:
  1. Create a shortcut to the batch file.
  2. Right-click on the shortcut and select "Properties".
  3. Click on the "Advanced" button.
  4. Check the box next to "Run as administrator".
  5. Click "OK" to save the changes.
Now, when you double-click the shortcut, the batch file will automatically run as an administrator without requiring you to right-click and select "Run as administrator" every time.



This trick will save you the extra step of having to right-click and select "Run as administrator" each time you run the batch file.

Unfortunately, it is not possible to use the same trick with the GPMC.msc console. This program must be run in the context of the needed domain, for example, from the domain's DC.