I am trying to make a PowerShell script which traverses all subdirectories and removes the hidden file attribute, but for some reason it doesn’t work.
This is something that is very easy for me to do in cmd, so I am surprised how difficult this is proving to be.
asked Dec 28, 2023 at 18:52
answered Dec 28, 2023 at 20:59
67 gold badges672 silver badges861 bronze badges
This blog post explains using PowerShell bitwise comparison operators to check and set bit flags. You can also use PowerShell to calculate bit flags by creating your own enum if desired.
We must first start with a (really) basic primer on decimal values and their binary equivalent.
Take the decimal value of 86. If we plot this in a binary table we can see that the binary equivalent of the decimal 86 is 01010110 by checking all of the bits set to 1 (64 + 16 + 4 + 2). This is 8-bit binary since there are only 8 bits.
MSB Bit Bit Bit Bit Bit Bit LSB
128 64 32 16 8 4 2 1
0 1 0 1 0 1 1 0
(MSB = most significant bit. LSB = least significant bit)
In the real-world, we use bits to represent MANY things. One of the most relatable examples is the ASCII table. Originally ASCII was 7-bits, meaning that it only allowed 128 different characters (64+32+16+8+4+2+1 = 127 characters plus all 0’s = 128 characters). But later this was extended to 8-bit binary, allowing 256 characters (128+64+32+16+8+4+2+1 = 255 characters plus all 0’s = 256 characters).
You can see in the link above that the decimal value of an upper-case K character is 75. Which we can represent in binary like so:
0 1 0 0 1 0 1 1
Another real-word example is colours! Think RGB colours (red/green/blue) such as 255/175/17. Each value represents an intensity of 8-bit colour, 0 being no colour and 255 being the most intense colour!
Now we have a brief understanding of decimal and binary and where they are used, we need to understand how we can check if bits are set and change them if required. And to do that, we must first understand some of the bitwise comparison operators. When comparing bits in binary strings we typically use AND, OR and XOR bitwise operators.
The Bitwise AND Operator
With the AND operator, if BOTH bit flags are 1 the result is a 1. Otherwise it’s a 0. For example:
(01001100 AND 11010110 = 01000100)
0 1 0 0 1 1 0 0
1 1 0 1 0 1 1 0
0 1 0 0 0 1 0 0
The Bitwise OR Operator
With the OR operator, if either bit is 1 or both bits are 1 the result is a 1. Otherwise it’s a 0. For example:
(01001100 OR 11010110 = 11011110)
1 1 0 1 1 1 1 0
The Bitwise XOR Operator
With the XOR operator if either bit is 1 and the other bit is 0, the result is a 1. But if both bits are 1 or both bits are 0, it’s a 0. For example:
(01001100 XOR 11010110 = 10011010)
1 0 0 1 1 0 1 0
Checking if Bits are Set using PowerShell
Let’s take our earlier example which represents the decimal value of 86:
If we want to check if bit 16 is set to 1, we can simply write:
0 0 0 1 0 0 0 0
The output of the binary and operator is 0 if the bit is NOT set. If it is set, it will return the bit flag value of 16 in this case.
Setting Bits using PowerShell
We might want the ability to set specific bit flags using PowerShell. So let’s take a real-word example of wanting to disable/enable a computer object in Active Directory.
In this case, we can see that the decimal value goes up to 67108864! Which is 2 to the power 26! Meaning 26-bits! But it makes no difference to us since our logic remains the same.
We can see in the documentation that the bit flag 2 represents ACCOUNTDISABLE. If this is set to 1 the account is disabled, and if it is set to 0 the account is enabled.
We can verify this and check if bit flag 2 is set like so:
If we wanted to see the binary equivalent of the decimal 4096 to do a manual check of the bit flag, we can write it like so:
Which equals (in binary): 1000000000000. In other words, the only flag that is set is for WORKSTATION_TRUST_ACCOUNT.
To set the ACCOUNTDISABLE flag, we want to create a bit mask representing that flag (decimal value of 2) and then when we compare both values, we can use the binary OR comparison in PowerShell to say “If either value is set to 1, our new value should be 1” like so:
1 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 0 0 1 0
$decimalval = 4096
$bitflag2 = 2
$newdecimalval = ($decimalval -bor $bitflag2)
write-host $newdecimalval
The new binary value now equals: 1000000000010. If we wanted to unset the flag and revert to a binary value of 1000000000000, we would need to use the XOR binary comparison operator. In other words, “if both values are a 1 or both values are a zero, set the flag to be 0”.
$decimalval = 4098
$bitflag2 = 2
$newdecimalval = ($decimalval -bxor $bitflag2)
write-host $newdecimalval
And when we tie it all together (try changing 4096 to 4098 back and forth to see the flag toggle):
Условный файл (массив) содержит такие строки:
string 1 with 能 char
string 2 with 能 char
string 3 with 予 char
string 4 with 能 能 char
string 5 without char
string 6
string 7 with 能 without char
Требуется, чтобы после обработки он выглядел так:
string 1 with 能\ char
string 2 with 能\ char
string 3 with 予\ char
string 4 with 能\ 能\ char
string 5 without char
string 6
string 7 with 能 without char
Попробовал сделать так:
string 1 with 能\ char
string 2 with 能\ char
string 3 with 予\ char
string 4 with 能\ 能 char
string 4 with 能 能\ char
Пробовал считывать всё одной строкой с применением той же обработки:
string 1 with 能\ char
string 2 with 能 char
string 3 with 予 char
string 4 with 能 能 char
string 5 without char
string 6
string 7 with 能 without char
string 1 with 能 char
string 2 with 能\ char
string 3 with 予\ char
string 4 with 能 能 char
string 5 without char
string 6
string 7 with 能 without char
string 1 with 能 char
string 2 with 能 char
string 3 with 予\ char
string 4 with 能 能 char
string 5 without char
string 6
string 7 with 能 without char
string 1 with 能 char
string 2 with 能 char
string 3 with 予 char
string 4 with 能\ 能 char
string 5 without char
string 6
string 7 with 能 without char
string 1 with 能 char
string 2 with 能 char
string 3 with 予 char
string 4 with 能 能\ char
string 5 without char
string 6
string 7 with 能 without char
Подскажите, как всё же обработать строки по данному условию и поместить как подпадающие под условие и обработанные строки, так и не подпадающие и не обработанные строки в тот же или другой файл (массив)?
How to modify the font size in a .lnk file using PowerShell
The font size, and other properties, in a .lnk file can be edited by searching through its internal structures for the structure that has the desired property as a member. In the case of changing the font size, the desired structure is CONSOLE_PROPS, and the desired member is “The two most significant bytes” of FontSize, which contain the font height.
Load the Shortcut File: Start by loading the .lnk file into a byte array. This allows us to edit the file in memory.
Identify Structures: Determine which structures are present, and will need to be navigated, in the file by reading the link flags. Also, move $pointer past the first, and only mandatory structure, ShellLinkHeader.
Navigate Identified Structures: Increment $pointer, moving past each existing structure, until the arriving at the extra data section of the .lnk file.
Write Changes to File: After modifying the font height, save the changes back to the file. Optionally, modify this part to save to a new file instead.
The above code edits only the font height. You can similarly modify other properties in any structure, not just CONSOLE_PROPS, by navigating to the correct structure, and then navigating to the desired property in that structure.
In this article, we will explore this problem and provide you with multiple solutions to restore the missing option.
Table of Contents
What are Wi-Fi Bands
Wi-Fi bands refer to the two main frequency ranges used for wireless communication: the 2.4GHz band and the 5GHz band. These bands determine the frequency at which your Wi-Fi signal operates.
The 2.4GHz band has been around for a long time and is commonly used by many devices. It offers a longer range and better ability to penetrate through walls and other obstacles. However, because it is widely used, it can suffer from congestion and interference from other devices like cordless phones and microwaves. That said, it results in slower speeds and reduced performance.
On the other hand, the 5GHz band provides faster speeds and is less prone to interference. It is ideal for bandwidth-intensive activities like online gaming, streaming high-definition videos, and transferring large files. However, its shorter range means that it may not reach as far or penetrate through obstacles as effectively as the 2.4GHz band.
Windows allow you to manually select the preferred Wi-Fi band for your computer. As a result, you can optimize your Wi-Fi connection based on factors such as signal strength, network congestion, and device compatibility. This allows you to maximize your wireless performance and ensure a stable connection.
Note: Not all devices support both Wi-Fi bands. Older devices may only be compatible with the 2.4GHz band, while newer devices often support both bands. Therefore, having the ability to manually select the preferred band can be valuable in ensuring the best performance and compatibility for your specific device and network environment.
Preferred Band option in Wi-Fi properties
Let us show you how to fix the issue and restore the “Preferred Band” option.
Fix Preferred Band Option Not Showing
There are several effective ways through which you can bring back the preferred bands option in Wi-Fi properties. Perform the solutions below in the given chronological order to resolve the issue.
Check Network Adapter’s Compatibility
In order to bring back the “Preferred Band” option, you must check whether your system is compatible with these bands or not. Here is how to do it:
Using this information, you can now determine if your wireless adapter even supports more than one bands. If only one band is supported, the “Preferred Band” option may be missing, and will be of no use even if it was present.
Change Router Settings
The easiest way to resolve this problem is by changing the settings of your Wi-Fi router itself.
If you cannot find the option to change your preferred Wi-Fi band from the computer, then you can change operating band on the router itself. Here is how to do it:
This will now change the operating channel for your Wi-Fi, and simultaneously change the Wi-Fi band for all connected devices.
However, if this soluton did not work for you, or the option was mising in your router’s settings, there perform the remianing solutions below.
Configure Preferred Band using PowerShell
Sometimes an outdated driver also impacts the functionality of preferred bands in Wi-Fi properties. That said, make sure to check the driver version installed and update it if needed. Below are the simple steps that can help you update your Wi-Fi driver.
Note: To manually update the Wi-Fi driver, select the second option in Step 3 i.e., Browse my computer for driver software option. Then, navigate to the folder on your computer where you downloaded the Wi-Fi adapter driver and select it for the update.
Reinstall the Wi-Fi Driver
There are times when a corrupted Wi-Fi driver is installed. In such cases, you can try reinstalling it to resolve the issues. Here is how you can reinstall a Wi-Fi driver:
Roll Back the Wi-Fi Driver Update
Whether it’s optimizing your Wi-Fi connection for faster speeds or reducing interference, the “Preferred Band” option plays a crucial role in enhancing your wireless networking experience.


