Automatically Deleting Files and Folders When Disk Space is Low

If you need to automatically delete files and folders when disk space on your drive falls below a certain threshold, you can use a PowerShell script to accomplish this task. Here’s how you can set it up.

PowerShell Script

This script will delete files and directories under a specified path when the available disk space is less than 5 GB.

# Define the path to the directory
$directoryPath = "C:\DeleteFilesFolder\

# Set the threshold for disk space (in bytes)
$threshold = 5GB

# Get the drive information
$drive = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Root -eq "C:\" }

# Check the available free space on the drive
if ($drive.Free -lt $threshold) {
# Get all files in the specified directory and subdirectories
$files = Get-ChildItem -Path $directoryPath -Recurse -File

# Loop through and delete each file
foreach ($file in $files) {
Remove-Item -Path $file.FullName -Force
Write-Output "Deleted file: $($file.FullName)"
}

# Get all directories in the specified directory and subdirectories
$directories = Get-ChildItem -Path $directoryPath -Recurse -Directory | Sort-Object -Property FullName -Descending

# Loop through and delete each directory if it is empty
foreach ($directory in $directories) {
Remove-Item -Path $directory.FullName -Recurse -Force
Write-Output "Deleted directory: $($directory.FullName)"
}

Write-Output "All files and directories in $directoryPath and its subdirectories have been deleted due to low disk space."
} else {
Write-Output "Sufficient disk space available: $($drive.Free / 1GB) GB free."
}

Explanation of the Script

  1. $directoryPath: Specifies the directory path where files and folders will be deleted.
  2. $threshold: Sets the disk space threshold to 5 GB.
  3. $drive: Checks the free space available on the C: drive.
  4. if ($drive.Free -lt $threshold): Checks if the available free space is less than 5 GB.
  5. Get-ChildItem -Path $directoryPath -Recurse -File: Gets all files in the specified directory and subdirectories.
  6. Remove-Item -Path $file.FullName -Force: Deletes each file without user interaction.
  7. Get-ChildItem -Path $directoryPath -Recurse -Directory | Sort-Object -Property FullName -Descending: Gets all directories in descending order to ensure deletion from the deepest level first.
  8. foreach ($directory in $directories): Deletes each directory and its contents without user interaction if it’s empty.

Running the Script Manually

  1. Open PowerShell as Administrator.
  2. Run the Script:
    C:\Scripts\ClearIncomingQueue.ps1

Automating the Script with Task Scheduler

You can use Task Scheduler to automate the script.

  1. Open Task Scheduler: Open it by typing taskschd.msc in the Run dialog.
  2. Create a New Task:
    • Right-click and select “Create Task”.
    • General tab: Name your task (e.g., “Clear Files and Folders”).
    • Triggers tab: Click “New” and choose the schedule (e.g., daily).
    • Actions tab: Click “New” and select “Start a program”. Enter powershell.exe as the program/script.
    • In the “Add arguments (optional)” field, enter:
      -File "C:\Scripts\ClearIncomingQueue.ps1"
    • Conditions tab: Check “Start the task only if the computer is on AC power”.
    • Settings tab: Check “If the task fails, restart every” and set an interval.

This setup ensures that files and directories under the specified path are automatically deleted when the available disk space falls below 5 GB, without any user interaction.

Simple , Easy, Useful

Have a nice day !

What is VMware Heap Size? How to Clear VMware Heap Size ?

Heap size in a VMware infrastructure refers to a portion of memory used to manage virtual machines and VMware-specific operations. The heap is dynamically allocated memory that can be released back to the operating system. It is used to store runtime data required for virtual machines, applications, and system processes.

Factors Increasing Heap Usage:

  • Virtual Machine Density: More VMs increase heap usage.
  • Application Requirements: Applications with high memory needs can raise heap usage.
  • Memory Leaks: Leaks in applications or processes can consume heap memory.
  • System and Service Updates: Updates may temporarily increase heap usage.
  • Configuration Changes: Adjustments in settings can impact heap usage.

Monitoring heap usage is crucial to prevent performance issues and maintain system health.

Methods to Clear VMware Heap Size:

You might need to clear the heap space on your VMware ESXi servers. Usually, the heap space is automatically managed to enhance the functionality of ESXi servers and prevent memory leaks. However, manual intervention might be necessary in certain situations. Here are some methods to consider:

  • Restart the ESXi Host: This is the simplest and most effective method if possible. It clears all memory and resets the heap space.
  • Restart Services: If restarting the host is not an option, you can clear the heap space by restarting key services. For example, use the commands /etc/init.d/hostd restart and /etc/init.d/vpxa restart to restart the management network service.
  • Check Advanced Settings: Some advanced settings, like Config.HostAgent.plugins.solo.enableMob, can affect heap size. Adjusting these settings as specified in VMware’s knowledge base might resolve issues.
  • Manage Memory Resources: Identify and address virtual machines or applications causing high memory usage to indirectly reduce heap usage.
  • Check Log Files: Log files in the /var/log directory, especially vmkernel.log and hostd.log, can help identify and troubleshoot heap issues.

If the methods above do not resolve the problem, you will need to contact VMware support for further assistance.

 

Have a nice day !

How to Add Multiple Subnets to Active Directory Sites and Services

Your infrastructure may have multiple locations and, depending on those locations, many network subnets. In some cases, you may choose to use multiple network subnets to separate services even within a single data centre.

If you are using Active Directory as the directory service in your infrastructure, you need to add these subnets to ‘Sites’ under "Active Directory Sites and Services" and ‘Subnets’ under that.

You can add subnets most simply with a few right clicks on the "Active Directory Sites and Services" console. This is usually the method that everyone uses.

This process also has an equivalent in the PowerShell world. Although it is generally not preferred by those who do not like to work with scripts, there is no better method than this when you want to do batch processing.

If you have hundreds of subnets that you need to define, you can do it in seconds with the following script.

# CSVPath
$csvFilePath = "C:\Subnet.csv"

# CSVRead
$subnets = Import-Csv -Path $csvFilePath

#Created
foreach ($subnet in $subnets) {

$name = $subnet.Name
$site = $subnet.Site
$description = $subnet.Description

try
{
New-ADReplicationSubnet -Name $name -Site $site -Description $description
Write-Host "Subnet $name added."

}catch{
Write-Host "Subnet $name failed: $_"
}
}

 

For mote detailed information ;

Have a nice day!

Republic Day: 100th Anniversary of The Republic of Türkiye

The Turkish Republic is celebrating its Centennial anniversary today (29 October).

Republic Day in Turkey, also known as Cumhuriyet Bayramı, is celebrated on October 29th each year to commemorate the proclamation of The Republic of Turkey. The 100th anniversary of the Republic of Turkey was celebrated on October 29, 2023, marking a significant milestone in Turkish history.

On October 29, 1923, Mustafa Kemal Atatürk, the founder of modern Turkey, officially declared the establishment of The Republic of Turkey, ending the Ottoman Empire’s rule and transforming Turkey into a modern, secular, and democratic nation. This momentous event marked the beginning of a new era for the country and its people.

Republic Day is celebrated with various events and activities across Turkey. These celebrations typically include parades, fireworks, concerts, and other public gatherings. People often adorn their homes and public buildings with the Turkish flag, and the national anthem is sung with great pride.

The 100th anniversary of the Republic of Turkey is an especially significant occasion, and it is likely to be marked with even more grandiose celebrations and festivities, reflecting the importance of this historical milestone in the country’s journey towards modernization and democracy.

When Mustafa Kemal Atatürk proclaimed the Republic of Turkey on October 29, 1923, he made a famous speech to the Turkish Grand National Assembly. In his speech, he expressed his vision for the new Turkish state and emphasized the principles that would guide its transformation. Here is an excerpt from Atatürk's speech on that historic day:

"Turkish people, your existence, your future, your honor and your happiness are in the faith, the determination and the fervor of manhood that are characteristic of you. From the day I took the leadership of the war of salvation until today, the strength of this faith, determination and fervor has never abandoned me, and I have been helped by it. I am grateful to you all for this great service you have done, which I could never repay.
The Republic of Turkey shall be a state of justice, a state where the rule of law, the principle of the equality of citizens before the law, and the principle of the protection of human rights shall be established in accordance with the concepts and understanding of contemporary civilization and law, and which serves its people in accordance with these principles.
A citizen of the Turkish Republic, whatever his religion or race may be, whatever his beliefs or inclinations may be, is a person who has full citizenship rights and responsibilities."

In this speech, Atatürk emphasized the principles of democracy, secularism, and the equality of all citizens, regardless of their religion or ethnicity. He laid the foundation for a modern, secular, and democratic republic, which has since been enshrined in the Turkish Constitution. Atatürk's vision and leadership played a crucial role in shaping modern Turkey.

 

"How happy is the one who says I am a Turk"

Atatürk used this phrase to emphasize the importance of national identity and unity, encouraging citizens to take pride in their Turkish heritage and culture. It signifies a sense of belonging and commitment to the Turkish nation. The motto highlights the idea that being a part of the Turkish nation is a source of happiness and pride.

 

"Peace at home Peace in the World"

This motto reflects Atatürk’s foreign policy principles and his belief that establishing and maintaining peace within a nation is crucial for promoting peace on a global scale.
Atatürk believed that a strong, stable, and united nation at home would contribute to greater harmony and cooperation with other nations in the world. This principle underscores the idea that a nation’s internal stability and peace are closely linked to its ability to maintain peaceful relations with other countries.
The motto “Peace at home, peace in the world” is a call for nations to prioritize diplomacy, cooperation, and peaceful solutions to conflicts rather than resorting to violence or war. It conveys the importance of avoiding external conflicts and focusing on domestic prosperity and harmony as a means to promote global peace and stability. This principle remains an important part of Turkey’s foreign policy and diplomatic efforts.

 

 

 

"How happy is the one who says I am a Turk"

Netlogon Protocol Changes – News !

As you know, Microsoft Netlogon protocol change process was activated with the November 8, 2022 updates (KB5021130 – CVE-2022-38023 ).

In previous announcements, “Enforcement by Default” would be activated with the April 11, 2023 updates, but it was postponed with new announcement which is 13 June, 2023.

 

By the way after the Windows updates that are dated on or after November 8, 2022 Windows updates are installed, you can add the “RequireSeal” key below.

Registry Key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters

Value: RequireSeal

Data Type: REG_DWORD

Data:  0 – Disabled

 1 – Compatibility mode. Windows domain controllers will require that Netlogon clients use RPC Seal if they are running Windows, or if they are acting as either domain controllers or Trust accounts.

2 – Enforcement mode. All clients are required to use RPC Seal, unless they are added to the “Domain Controller: Allow vulnerable Netlogon secure channel connections” group policy object (GPO).

If you have more than one Domain Controller in your environment, you can distribute the registry key with the group policy method.

Or you can choose to use Powershell :

New-ItemProperty -Path "HKLM:\System\CurrentControlSet\Services\Netlogon\Parameters" -Name RequireSeal -Value DATA -PropertyType DWORD –Force

 

Note: Events 5838,5839 and 5840,5841 can be checked in the System Event Log on DCs with November 2022 updates installed to detect applications that may have problems.

 

 

Have a nice day!

How to Upgrade Failover Cluster Functional Level

When you add new nodes with a higher operating system to your Windows Failover cluster environment, you will receive warnings about "Functional Level" mismatch in your failover cluster logs.

The main reason for these warnings is that the operating systems and functional levels of the clusters connected to the nodes in your environment are different from each other.

You can follow the steps below to change the functional level compatibility;

  • To view the Failover Cluster Functional Level version
    Get-Cluster | select ClusterFunctionalLevel
  • To upgrade the Failover Cluster Functional Level version
    Update-ClusterFunctionalLevel
  • To view the upgrade process of the Failover Cluster Functional Level version
    Get-Cluster | select ClusterFunctionalLevel
  • In Windows Server 2019 the Clustering team introduced a new PowerShell cmdlet to check how many nodes of the cluster are running on which level
    "Get-ClusterNodeSupportedVersion" helps you to identify the Cluster Functional Level and the Cluster Upgrade Version.

The table below shows the values and each corresponding functional level:

 

For more detailed information;

Have a nice day!

How to Fix Failed While Applying Switch Port Settings ‘Ethernet Switch Port VLAN Settings’

If you get the following error when you want to make a VLAN change on your virtual server that you use on Hyperv;

"Error applying Network Adapter changes"
"The operation failed. Failed while applying switch port settings 'Ethernet Switch Port VLAN Settings' on switch 'Vs': One or more arguments are invalid (0x80070057)."

The root cause of this problem is the network mode you use on your virtual server, for example F5 virtual server appliance.
Let’s continue with the example there are more than one ethernet card over the F5 virtual server appliance, some of which are trunk and some are access mode.

You will get an error when you make the VLAN change on the Trunk mode card from the Hyper V Failover Cluster gui.

To fix this problem, you can follow the steps below;

  • First of all, we view the cards and their modes on the virtual server.
    Get-VMNetworkAdapterVlan -VMName servername
  • The tag is removed the network card with trunk mode.
    Set-VMNetworkAdapterVlan -VMName servername -VMNetworkAdapterName NIC3 -untagged
  • We define access mode and VLAN ID.
    Set-VMNetworkAdapterVlan -VMName servername -VMNetworkAdapterName NIC3 -Access -VlanId 715
  • To view the change made.
    Get-VMNetworkAdapterVlan -VMName servername

Have a nice day!

 

March 2023 Exchange Server Security Updates

Microsoft Exchange Servers security updates have been released for March 2023.

These updates are available for the following specific versions of Exchange Server:

Exchange Server 2013 CU23 SU21 (Microsoft Exchange Server 2013 will reach its end of support on April 11, 2023)
Exchange Server 2016 CU23 SU7
Exchange Server 2019 CU11 SU11 & CU12 SU7

The recommendation is to install these updates immediately to protect your environment.
In the scenario where you do a Cumulative Update(CU), you need to make security updates. Otherwise, remember that you have to do the Cumulative Update(CU) first and then the Security Update(SU).

Inventory your Exchange Servers to determine which updates –> “Exchange Server Health Checker
Choose your current CU and your target CU to get directions –>  “Exchange Update Wizard
If you encounter errors during or after installation of Exchange Server –> “Exchange Setup Assist

Note: Don't double-click the 'MSP file' to run it. Run Command Prompt (not Powershell) as an Administrator.

Issues resolved with this update:

  • EWS web application pool stops after the February 2023 Security Update is installed .
    ⇒If you have applied a workaround for this issue, you should roll it back after the March security update.
  • Exchange Server 2016 or 2019 who have non-default applications installed through ECP add-ins, the ECP add-ins page might be broken after the February 2023 Security Update is installed
    ⇒The issue is expected to be resolved with the March security update.
  • The Get-App and GetAppManifests applications fail and return an exception, “MSExchangeServicesAppPool” application pool to repeat in the same order after the February 2023 Security Update is installed .
    ⇒The issue has been resolved with the March security update.
  • Exchange Toolbox and Queue Viewer fails after Certificate Signing of PowerShell Serialization Payload is enabled after the Janurary 2023 or the February 2023 Security Update is installed.
    ⇒The issue has been resolved with the March security update for servers running the Mailbox Role, but this issue persists on other servers with management console installed.

Have a nice day!

February 2023 Exchange Server Security Updates

Microsoft Exchange Servers security updates have been released for February 2023.

These updates are available for the following specific versions of Exchange Server:

Exchange Server 2013 CU23 SU20 (Microsoft Exchange Server 2013 will reach its end of support on April 11, 2023)
Exchange Server 2016 CU23 SU6
Exchange Server 2019 CU11 SU10 & CU12 SU6

The recommendation is to install these updates immediately to protect your environment.
In the scenario where you do a Cumulative Update(CU), you need to make security updates. Otherwise, remember that you have to do the Cumulative Update(CU) first and then the Security Update(SU).

Inventory your Exchange Servers to determine which updates –> “Exchange Server Health Checker
Choose your current CU and your target CU to get directions –>  “Exchange Update Wizard
If you encounter errors during or after installation of Exchange Server –> “Exchange Setup Assist

 

Note: Don't double-click the 'MSP file' to run it. Run Command Prompt (not Powershell) as an Administrator.

 

Have a nice day!

How to Fix TLS “SchUseStrongCryptoValue: Null

If you are getting “StrongCrypto” error as below after configuring TLS on your Microsoft Exchange Servers;

v4.0.30319 SchUseStrongCryptoValue: NULL --- Error: Value should be defined in registry for consistent results.
v4.0.30319 WowSchUseStrongCryptoValue: NULL --- Error: Value should be defined in registry for consistent results.

The values you need to define for “StrongCrypto” are as follows:

Set “Strong Cryptography” on 32-bit .Net Framework

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

 

Set “Strong Cryptography” on 64-bit .Net Framework

Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord

 

Have a nice day!