How to add missing windows services in WMI monitoring with Non-Administrator account

Update: The purpose in this blogpost is about giving permission of specific windows service to specific monitoring user. So, you can replace step-6 (setting DNS service permission to specific account that will monitor service) with easier methods in my new blog post.

There are three methods for monitoring windows servers:
  1. By installing Agents (such as Zabbix,SCOM Agents).
  2. SNMP v1,v2, v3 regardless of platforms.
  3. WMI Monitor for windows servers.
And today, I’m going to make the WMI monitoring in a couple of steps, plus how to monitor the missing windows services that is unavailable in the default monitor method. Here, I’ll use the Microsoft DNS Server as a monitoring client for DNS Service + basic resource monitoring.

Continue reading “How to add missing windows services in WMI monitoring with Non-Administrator account”

PowerShell: Join Domain Users to Any Specific OU

I have been looking for ways for automatic domain join so that the end-users can do by themselves without special  knowledge. There are serveral scripts I found on google that make it work, but none of them seems to be an all-in-one solution.Moreover, I don’t want to do usernames/password put in text files that are delivered to each user. So, I decided to make a complete script for automatic-domain-join  of users.

What this script will do:
1) Test the DNS Server is reacheable and if OK, change the users’ DNS setting to point to Domain Controller.
2) Prompt for username/password to join to domain, no need to put username/pass with the script file.
3) Users can choose their own OU for their domain-join-process, so Admin doesn’t need to move thier computer objects to specific OU after domain join. ( the one I liked most & the reason why I wrote this script xP ).

Things you need to do:
1) Modify the Admin section of the script to your needs

2) Delegate All OUs to create computer objects for domain users so that they themselves can join to the domain. (This is the one that took my most time troubleshooting the access denied error.)
I would recommend to create the new security group, delegate the permission to that group and put the domain users into the group. Because it’s more safer to delete (rather than revoke delegation permission) that security group after all users are joined to domain.

3) Some Clients may need to enable powershell script execution policy to remotesigned, so that powershell scripts can execute. You can do it by another batch script that call the powershell script ,,, etc… etc..

1) Delegating OU Permission
Only the the Admin and Account Operator roles have permissions to create computer & users objects in any OU. We need some little right for users to perform themselves. But granting Account Operator roles to every domain users is a the one we should never do. So, I will give only necessary permissions.

From Active Directory Users and Computers, Choose the parent OU you want to delegate.

Fig-1:Permission Delegation for specific OU

Delegate the security group to create computer objects in Active Directory.

OU Delegation
Fig-2: Add OU delegation to specific security group

On the next page, choose Create a custom task to delegate.

Choose Computer Objects and check the “Create selected objects in this folder” as shown in Fig-3.

Fig-3: Choose resources for OU delegation

Step 5:
Customize the permission Here I select the Write and Create all child objects. Others default.

Add custom permission for OUO delegation
Fig-4: Add custom permission for delegation

So far, we finished about delegating permission. Now, the client can run the script on his computer. See Fig-5.

Domain Join Powershell Script
Fig-5: Demo of running the script

Powershell: Find the Windows Service of a Running Process

Today, I need to find the registered services of some running processes & its installed path. Here we can use some third-party tools, such as Process Explorer, Process Hacker and find each process’s associated service. But, I want to use the built-in options, so WMI with Powershell is the way to go. I also checked the windows task manager and it only listed the service & it’s associated service name, not the process name. So, I need to do some scripting to get it through.
It’s the sample output.

Find a running process's service by Powershell and WMI
Fig-1: Find a running process’s service

How to Enable PowerShell Remoting in Easy Way

Empower yourself with the ability to perform administrative tasks on multiple servers remotely, even while users are logged in or away. PowerShell remoting, available since PowerShell version 2 and above, opens up a world of possibilities for system administrators.

If you’re using Windows 7, 2008R2, or newer, PowerShell remoting is already at your fingertips. However, for legacy environments like Server 2003 and Windows XP, a few additional steps are required. You’ll need to install the Server 2003 Service Pack 2 and the Windows Management Framework.

Things to do on the destination computer

This is the computer on which you want to execute the remote commands. On this machine, run PowerShell as an administrator and execute the command.

Set-ExecutionPolicy RemoteSigned

Then, initialize WinRM with the following command:

winrm quickconfig -quiet

On the source computer, you’ll also need to start the WinRM service temporarily to configure settings. Remember to add the destination computers to the trusted hosts list for communication. This ensures a secure connection between local and remote systems. Other words, in trustedhosts list, you can define the destination computers by IP addresses separated by commas or using wildcard as follows.
(Note: if you use the HTTPs, you need to generate the certificate and add to each computer, so it would be more efficient to enroll the certificate via GPO in domain environment. I’ll write the other article for this scenario)

Things to do on Source Computer

This is the computer that will initiate the connection. In the elevated PowerShell session of source computer, type:

winrm quickconfig -quiet
Set-Item WSMan:\localhost\Client\TrustedHosts -Value "192.168.1.*"

Figure 1:  WinRM Quick Configuration

Figure 2: Added Computers to Trusted Hosts

Let’s test the Connection

You can use Test-WSman to test if the powershell remoting works. The following command will test the connection.

Test-WSman -ComputerName -Credential (Get-Credential) -Authentication default

Figure 3: Testing the Connection

Using remote script execution (example)

You can execute remote scripts on multiple computers, you can put the computers names as IPs or hostnames in text file. Here is the one I show as example.

How to check multiple Forward and Reverse DNS records in Powershell

Tired of spending hours manually querying DNS records? A few days ago, I had to query over 100 DNS records to determine if both forward and reverse records were working properly. Making the nslookup over 100 records is a time-consuming and daunting task for a system administrator. Therefore, I decided to write a powershell script to automate the job.

You will need to put the hostnames in hostnames.txt file in the same directory as the script file and run the script.


How to convert VDI to VMDK or VHD in easy way

While third-party tools like VMware Standalone Converter and Starwind V-2-V exist for converting VDI to VMDK or VHD, leveraging VirtualBox’s native capabilities offers a speedy alternative. You can follow our step-by-step guide, applicable to both Windows and Linux environments, and optimize your virtualization workflow effortlessly.
Go to virtualbox install directory in windows command prompt and type the following command.

VBoxManage.exe clonehd c:\DiskVirtualold-disk.vdi c:\DiskVirtualnew-disk.vmdk –format vmdk –type normal –variant standard

Now, you can attach the converted vdisk to the VM of your choice.

See the example screenshots below.

How to stop unresponsive Windows Service

In windows system administration, understanding how to stop windows services which is not responding or hanged is a crucial skill. Whether you’re troubleshooting a misbehaving process or aiming to optimize system resources, knowing the ins and outs of service management can significantly impact your computing experience.

In this example, let’s forcefully stop the windows time service by killing the associated process.

First, query the service PID via NT service controller.

sc queryex <servicename>
sc queryex w32time
Note: you can find the service name from services.msc in Run box. Here w32time for Windows Time Service.

2) Note the PID of the service. Here our process ID is 904

3) kill the process by PID.
tskill 904

Change grayed out Windows Service Startup Option

You might sometimes encounter grayed-out services, particularly in scenarios like antivirus programs where certain services are intentionally safeguarded against tampering for security purposes, can pose challenges in managing your system effectively. However, there are strategies you can employ to navigate this hurdle and regain control over these services.

Option 1 – Startup Config

1) type “msconfig” in Run box
2) in the service tab, uncheck the service
3) reboot the computer

Option 2 – Registry Modification

The second method involves accessing the Windows Registry, the central repository of system settings, and making targeted modifications to alter the startup type of the grayed-out services.
1) Go to HKLMSYSTEMCurrentControlSetServices
2) Double-Click the Start SubKey
3) Change the DWORD value to 0 to 4 according to your startup option. 2 for Automatic & 4 for Disabled.

Below are Start values and description according to the technet article.

0Boot (loaded by kernel loader). Components of the driver stack for the boot (startup) volume must be loaded by the kernel loader.
1System (loaded by I/O subsystem). Specifies that the driver is loaded at kernel initialization.
2Automatic (loaded by Service Control Manager). Specifies that the service is loaded or started automatically.
3Manual. Specifies that the service does not start until the user starts it manually, such as by using Device Manager.
4Disabled. Specifies that the service should not be started.