Skip to content

Blog

Run a PowerShell ps1 script hidden from view and scheduled on Task Scheduler for Windows

PowerShell scripts run in a visible window by default. To run one completely hidden, launch it through a .vbs script executed by wscript.

Set up the scheduled task like this:

  • In Task Scheduler
    • Action: Start a program
    • Program/script: wscript
    • Add arguments (optional): <path\to\the\.vbs\file>

The .vbs launcher script:

command = "powershell.exe -ExecutionPolicy Bypass C:\path\to\script.ps1"
set shell = CreateObject("WScript.Shell")
shell.Run command,0

Mount an SMB share and use iGPU on an unprivileged Debian 12 LXC container in Proxmox

Prerequisites:

Create an unprivileged Debian 12 LXC container.

Inside the LXC container, use the root user to create a non-root user. In this example the user is added to the sudo and docker groups after installing Docker inside the LXC container.

Terminal window
useradd -s /bin/bash -m -G sudo,docker ismael

Change the user password as needed.

Terminal window
su ismael
passwd

This user’s default UID:GID will be 1000:1000. If not, create it with:

Terminal window
useradd ismael -u 1000 -g 1000 -m -s /bin/bash -G sudo,docker

Take note of this UID:GID as it will be used to map the share in Proxmox. The share itself can live on another system; here an unRAID VM on the same host is used.

Create a user that can be mapped from the host to the LXC container. Without this step, the share ends up read-only inside the LXC container.

Proxmox maps the users and groups from the host to the LXC containers starting at UID:GID=100000:100000.

The created ismael user then:

  • Inside the LXC container UID: 1000
  • Inside the host UID: 101000

Create a group on the host with GID=101000 that will own the directory created for the SMB share

Terminal window
groupadd -g 101000 ismael

Create the same user that will be used inside the LXC container but with the right UID:GID combination

Terminal window
useradd ismael -u 101000 -g 101000 -m -s /bin/bash

Make a directory for the share

Terminal window
mkdir /mnt/media

Change the directory’s owner to the previously created user

Terminal window
chown ismael:ismael /mnt/media

Modify the /etc/fstab file to mount the SMB share on the directory we created

Terminal window
nano /etc/fstab

Copy this line inside the nano editor for /etc/fstab (note the guest part, as this SMB share has no password set)

Terminal window
//192.168.0.10/media /mnt/media cifs guest,rw,uid=1000,gid=1000,file_mode=0777,dir_mode=0777 0 0

For shares that require a password:

Terminal window
//192.168.0.10/media /mnt/media cifs username=<username>,password=<password>,rw,uid=1000,gid=1000,file_mode=0777,dir_mode=0777 0 0

Reload the changes to /etc/fstab before mounting

Terminal window
systemctl daemon-reload
mount -a

Create a mountpoint in your LXC container pointing to the created share directory

Terminal window
pct set 104 -mp0 /mnt/media,mp=/mnt/user/media

Start the LXC container and the share is mounted in /mnt/user/media, writable by the mapped user.

Coming soon…

Proxmox | automatically restore SMB/CIFS share connections

If at some point Proxmox loses connectivity with an SMB/CIFS share, it will not restore the connection by itself until a restart of the Proxmox node is performed. With the script below, the Proxmox node restores the connection automatically.

On the node’s shell, create a bash script that looks for mount points in /mnt/pve/ and unmounts them if they become stale:

Terminal window
nano remount.sh

Put this content into the file:

#!/bin/bash
list=$(ls /mnt/pve)
for i in $list
do
status=$(ls /mnt/pve/$i 2>&1)
if [[ $status =~ .*Stale.* ]]
then
umount /mnt/pve/$i
fi
done

Remember to make the script executable by the user creating it:

Terminal window
chmod 766 /root/remount.sh

Add a cron job for this script to run automatically:

Terminal window
* * * * * /root/remount.sh >/dev/null 2>&1

With that, any SMB/CIFS connections are restored automatically. That is because the service pvestatd tries to remount every SMB share every 10 seconds.

This approach could work for NFS shares too, but that possibility has not been tested.

Set up your SSH key-based authentication from Windows in a single line

Linux-to-Linux SSH setups are straightforward, but the Windows OpenSSH client needs a different approach to copy a generated key for password-less logins.

Generate your private and public keys in your Windows PowerShell shell

Section titled “Generate your private and public keys in your Windows PowerShell shell”

Execute the command below in Windows Terminal or any other terminal in Windows:

Terminal window
ssh-keygen

This generates the keys in the local host’s Windows profile directory under the .ssh/ sub-directory.

You can access it in this location on Windows by using the key combination Win + R and then entering this text in the Run window:

Terminal window
%userprofile%/.ssh/

That directory will include:

  • your generated private key id_rsa
  • your generated public key id_rsa.pub

The public key is the one we’ll copy into any remote host we want to connect without using a password.

The command below performs the equivalent of ssh-copy-id using the OpenSSH client on Windows. Edit user@host.address with the remote user and host IP/hostname.

Terminal window
type .ssh\id_rsa.pub | ssh user@host.address "mkdir -p .ssh && cat >> .ssh/authorized_keys"

This makes it possible to login directly to your remote host by simply using:

Terminal window
ssh user@host

Password-less login is now available: