Determining the location of a user's "My Documents" folder with PowerShell
I needed to move some files from one Windows 11 system that is no longer
being used, as the user is no longer working for the company, to another
Windows 11 system where the user of that system, Pam, is now handling a task
formerly handled by the prior employee, but while logged onto the account for
the user now handling the task on her system, I noticed that her
Documents folder was empty. The
Windows domain name
changed at that business a few years ago, so I thought that perhaps she
might be using a Documents directory associated with her account under
the prior domain name rather than the new one created for her new domain
login. You can determine the location of a user's "My Documents" directory,
which can be redirected to another location, including a network share
or another drive, by issuing the PowerShell command
[Environment]::GetFolderPath("MyDocuments"). E.g.:
Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.
Try the new cross-platform PowerShell https://aka.ms/pscore6
PS C:\Users\Pam> [Environment]::GetFolderPath("MyDocuments")
C:\Users\Pam\Documents
PS C:\Users\Pam>
The command utilizes the GetFolderPath method from the
System.Environment class to retrieve the path of special folders,
including "MyDocuments," for the user under whose context the script or command
is executed. This method correctly identifies the mapped location even if the
Documents folder has been redirected or moved from the default location.
In this case, I found that her "My Documents" directory was pointing to
the directory associated with the old domain name. Her "home" folder
was also pointing to the home folder that was in use for her account
in the old domain. You can type $home in a PowerShell window to
see that value. Or you can use $env:USERPROFILE to see the same
information.
PS C:\Users\Pam> $Home
C:\Users\Pam
PS C:\Users\Pam >$env:userprofile
C:\Users\Pam
PS C:\Users\Pam>
[/os/windows/PowerShell]
permanent link
PowerShell cmdlets to check remote connectivity and firewall rules
When I tried to establish a
Secure Shell (SSH)
connection to a Windows 11 PC at a remote location today, I was unable to
do so. I usually connect to the
Windows
domain controller at the location and establish the SSH connection
to the user's Windows 11 system through it, but that was not working. I thought
the problem was likely due to
McAfee stopping providing
firewall protection for incoming connections to ports on PCs as part of
their antivirus software, since the antivirus
software on PCs at that location was
McAfee Antivirus
Plus. When McAfee stopped providing that firewall service as part of
McAfee AntiVirus Plus, the software reverted firewall protection for incoming
connections to Microsoft's default firewall software,
Microsoft Defender
Firewall, aka Windows Firewall. When I check firewall protection on a
Windows system running McAfee AntiVirus Plus, I now see the following message:
McAfee and Windows Defender are now working side by side
Our Advanced Firewall provides enhanced protection by blocking risky
outgoing connections. Windows Defender Firewall provides protection for
incoming connections.
Keep both firewalls on for complete protection.
So I thought I likely needed to create similar firewall rules for
incoming connections in the Windows Firewall software as had existed
previously in the McAfee firewall software.
[ More Info ]
[/os/windows/PowerShell]
permanent link
Changing the "from" address of an email in mutt
To change the "from" address of a message in the
Mutt email
client while composing a message, you can use Esc-f, i.e., hit the
Esc and f keys simultaneously. You will see a "From:" field
appear near the bottom of the window with the current "from" address, which you
can edit to replace it with whatever you would like. E.g., in the example below,
I am changing the "from" address that the recipients of the message will see
from jdoe@example.com to newsletter@example.com (the email address is within
the angle
brackets with a descriptive identifier before it.
y:Send q:Abort t:To c:CC s:Subj a:Attach file d:Descrip ?:Help
From: Joe Doe <jdoe@example.com>
To: "Bruce K." <bkamen2145@gmail.com>
Cc: albusd@example.com
Bcc:
Subject: Re: July 2025 Newsletter
Reply-To:
Fcc: ~/sent
Security: None
-- Attachments
- I 1 /var/tmp/mutt-example-508-23668-418711[text/plain, 8bit, utf-8, 1.4K
-- Mutt: Compose [Approx. msg size: 1.4K Atts: 1]----------------------------
From: Newsletter <newsletter@example.com>
After I've retyped the "from" address to be the one I want to appear,
when I hit Enter, I will see the "from" address replaced with
the one I want and can then hit y to send the message to
recipients.
y:Send q:Abort t:To c:CC s:Subj a:Attach file d:Descrip ?:Help
From: Newsletter <newsletter@example.com>
To: "Bruce K." <bkamen2145@gmail.com>
Cc: albusd@example.com
Bcc:
Subject: Re: July 2025 Newsletter
Reply-To:
Fcc: ~/sent
Security: None
-- Attachments
- I 1 /var/tmp/mutt-example-508-23668-418711[text/plain, 8bit, utf-8, 1.4K
-- Mutt: Compose [Approx. msg size: 1.4K Atts: 1]----------------------------
For a way to change the "from" address from the command line, see
Using a command-line interface
(CLI) to send email with mutt.
[/network/email/clients/mutt]
permanent link
Changing the name of a Ubuntu Linux system from the command line
To change the name of a system running the
Ubuntu Linux operating
system from a
command-line
interface (CLI), i.e., a
terminal window,
you can take the following steps:
-
In the terminal window enter the command
sudo hostnamectl set-hostname newname where
newname is the new name you wish to assign to the system. E.g.:
jim@Firefly:~$ sudo hostnamectl set-hostname Smaug
[sudo: authenticate] Password:
jim@Firefly:~$
That will change the host name stored in /etc/hostname.
-
Then edit the
/etc/hosts file, replacing the old host name
there with the new one. E.g., if I had the following lines in the hosts
file, I would modify the second line containing the old host name.
127.0.0.1 localhost
127.0.1.1 Firefly
The 127.0.0.1 in the above lines is the
localhost IP address,
a loopback address that can be used when troubleshooting network issues.
Ubuntu also adds a 127.0.1.1 address in /etc/hosts with
the name you have assigned to the system. The name should match the
one in /etc/hostname, so change the name for the 127.0.1.1
address to the new name you wish to use.
References:
-
What is difference between localhost address 127.0.0.1 and 127.0.1.1
Updated: April 2, 2021
Ask Ubuntu
[/os/unix/linux/ubuntu]
permanent link
Changing the password for a LUKS encrypted partition on Linux
If you need to change the password, i.e., the encryption key, used to encrypt
a partition with
Linux Unified
Key Setup (LUKS) on a Linux system, you can open a terminal window and use
the command sudo cryptsetup luksChangeKey /dev/sdaX where
sdaX is the relevant partition. E.g., I needed to
change the password on a Ubuntu
Linux system where the user's data was stored on /dev/sda3.
jim@Firefly:~$ sudo cryptsetup luksChangeKey /dev/sda3
Enter passphrase to be changed:
Enter new passphrase:
Verify passphrase:
jim@Firefly:~$
If you don't know the designation for the encrypted partition, e.g., if I
didn't know it was sda3, I could use the lsblk
command (it is part of the
util-linux package) to determine it. E.g.:
jim@Firefly:~$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 4K 1 loop /snap/bare/5
loop1 7:1 0 73.9M 1 loop /snap/core22/2133
loop2 7:2 0 11.8M 1 loop /snap/desktop-security-center/59
loop3 7:3 0 247.6M 1 loop /snap/firefox/6966
loop4 7:4 0 11.1M 1 loop /snap/firmware-updater/167
loop5 7:5 0 91.7M 1 loop /snap/gtk-common-themes/1535
loop6 7:6 0 14.4M 1 loop /snap/prompting-client/104
loop7 7:7 0 516.2M 1 loop /snap/gnome-42-2204/226
loop8 7:8 0 17.5M 1 loop /snap/snap-store/1300
loop9 7:9 0 50.8M 1 loop /snap/snapd/25202
loop10 7:10 0 576K 1 loop /snap/snapd-desktop-integration/315
loop11 7:11 0 226.2M 1 loop /snap/thunderbird/812
sda 8:0 0 953.9G 0 disk
├─sda1 8:1 0 1G 0 part /boot/efi
├─sda2 8:2 0 2G 0 part /boot
└─sda3 8:3 0 950.8G 0 part
└─dm_crypt-0 252:0 0 950.8G 0 crypt
└─ubuntu--vg-ubuntu--lv
252:1 0 950.8G 0 lvm /
jim@Firefly:~$
From the above output, I can see that the disk drive in the system is
designated as sda and the encrypted partition is
sda3 (it is listed as type "crypt").
[ More Info ]
[/security/encryption/LUKS]
permanent link