Retour

Scripts utiles

Découvrez une sélection de scripts utiles pour améliorer votre productivité et simplifier vos tâches informatiques au quotidien.

Cette page fournit des scripts utiles pour modifier les noms d'hôtes sous macOS et supprimer le blocage USB sous Windows, en soulignant l'importance de vérifier leurs résultats avant leur mise en œuvre, car aucun support n'est disponible pour ces scripts.

Les scripts ci-dessous sont fournis « en l’état ». Veuillez vérifier leur résultat et leurs effets avant de les déployer. Nous n’offrons aucun support technique pour ces scripts.

 

 

macOS

Modification de tous les noms d'hôtes

#!/bin/bash# This script changes the hostname on macOS by updating:# - ComputerName: The user-friendly name seen in Sharing preferences.# - LocalHostName: The Bonjour name used on the local network (must be sanitized).# - HostName: The system's POSIX name.# - NetBIOSName: Used for SMB file sharing.## Usage: sudo ./change_hostname.sh NewHostname# Check if the new hostname is providedif [ "$#" -ne 1 ]; then    echo "Usage: sudo $0 <new_hostname>"    exit 1fiNEW_HOSTNAME="$1"# Sanitize the new hostname for LocalHostName (Bonjour) requirements:# - Convert to lowercase, remove invalid characters (keeping only letters, numbers, and hyphens).SANITIZED_HOSTNAME=$(echo "$NEW_HOSTNAME" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]-')echo "Changing hostname to: $NEW_HOSTNAME"echo "Using sanitized LocalHostName: $SANITIZED_HOSTNAME"# Change the ComputerName (visible in Sharing settings)sudo scutil --set ComputerName "$NEW_HOSTNAME"# Change the LocalHostName (used for Bonjour)sudo scutil --set LocalHostName "$SANITIZED_HOSTNAME"# Change the HostName (the underlying POSIX hostname)sudo scutil --set HostName "$NEW_HOSTNAME"# Optionally, change the NetBIOS name for SMB file sharingsudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server NetBIOSName -string "$NEW_HOSTNAME"echo "Hostname successfully updated!"echo "A reboot might be required for all changes to fully take effect."

 

Windows

Supprimer le blocage USB

# Run as AdminWrite-Host "Removing RemovableStorage Blocking..." -ForegroundColor Cyan# CSP Paths$paths = @(  "HKLM:\SOFTWARE\Microsoft\PolicyManager\current\device\ADMX_RemovableStorage",  "HKLM:\SOFTWARE\Microsoft\PolicyManager\current\user\ADMX_RemovableStorage")foreach ($path in $paths) {    if (Test-Path $path) {        Remove-Item -Path $path -Recurse -Force        Write-Host "Key removed : $path" -ForegroundColor Green    } else {        Write-Host "Key not found : $path" -ForegroundColor Yellow    }}# Refresh policiesgpupdate /forceWrite-Host "✅ USB should now be usable" -ForegroundColor Green

 

Cet article vous a-t-il aidé ?

Give feedback about this article

Vous ne trouvez pas ce que vous cherchez ?

Notre équipe de service client est là pour vous.

Nous contacter

Knowledge Base Software powered by Helpjuice