Posts

Showing posts with the label PowerShell

Rename devices with PowerShell and Microsoft Intune

Image
Renaming a device manually is quick and easy when we only have one device to fix. But when it comes to doing a large number of devices, then it is better to automate this action. Today, there is the method via CSP but which can have a rather random behavior, in particular on the reporting, console side. I therefore share with you a PowerShell script which, deployed with Microsoft Intune, will allow you to quickly rename your machines. Script overview This script detects the type of device used:  If it's a virtual machine , it takes the defined prefix  (CCMT in my example)  and adds a numeric complement generated with Get-Random command For physical machines , it retrieves the serial number and adds the prefix  (CCMT in my example) The user is informed that his device has received changes and that it will restart automatically in a few minutes. The script is available on Github :  Link Script integration & deployment Prerequisites The prerequisites are: Conve...

How to install windows Sandbox with PowerShell

Image
Windows Sandbox provides a lightweight desktop environment to safely run applications in isolation. Software installed inside the Windows Sandbox environment remains "sandboxed" and runs separately from the host machine. A sandbox is temporary. When it's closed, all the software and files and the state are deleted. You get a brand-new instance of the sandbox every time you open the application. Note, however, that as of Windows 11 Build 22509, your data will persist through a restart initiated from inside the virtualized environment useful for installing applications that require the OS to reboot. Software and applications installed on the host aren't directly available in the sandbox. If you need specific applications available inside the Windows Sandbox environment, they must be explicitly installed within the environment. Sources :  https://learn.microsoft.com/en-us/windows/security/threat-protection/windows-sandbox/windows-sandbox-overview Script presentation Scri...

How to create a virtual machine on Hyper-V with PowerShell

Image
 Presentation When we want to set up a lab, we are forced to multiply the clicks to create our environment. To make my task easier, I created a script with two virtual machine templates. Github link :   https://github.com/ChrisMogis/Create_VM_HyperV.ps1.git  The first model proposes: 2 vCPU 2Gb  of memory 60Gb  hard drive The second model proposes :  4 vCPU 4Gb  of memory 80Gb  fard drive Prerequisites CPU compatible with virtualization instructions Virtualization activated in UEFI Windows 10/11 Pro or Enterprise license Hyper-V is available on your computer How to install Hyper-V :  https://www.ccmtune.fr/2022/08/how-to-install-hyper-v-feature-on.html Variables avalables in the Script VM naming Two variables used for create the name of vitrual machine $VMNumber  =  Get Random $VMName  =  "CCMT" + $VMNumber Virtual Switch This variable is used to name the virtual switch that will be created when you run the script.  (...

How to install Hyper-V feature on Windows 11 client

Image
Presentation The Hyper-V virtualization module allows you to create one or more virtual machines on a physical server or a PC. In our case, we are going to install it on a PC equipped with Windows 11.  Note that you need a Windows Professional or Enterprise edition license for this. Prerequisites CPU compatible with virtualization instructions Virtualization activated in UEFI Windows 10/11 Pro or Enterprise license Install feature Installation via Windows's GUI Go to Start Menu / Settings / Apps / Optional Features Click More optional features Search Hyper-V , tick the Hyper-V and click OK Windows proceed on Hyper-V installation. After this step, a computer restart is required. Installation with PowerShell Open Powershell with admin right Insert this command line :  Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All Check installation with this command line :   (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V).State

User Assistant - Tool for End User

Image
Presentation This tool aims to gather and provide the end user with options to perform simple actions without having to search everywhere in Windows. Github link :   https://github.com/ChrisMogis/EndUser_assistant.ps1/blob/main/EndUser_Assistant.ps1 Options available List of actions : Computer information (Device Name, IP, @Mac, OS) Run remote control (msra) Data backup Internet connection test Clear cache DNS Reset network connection Restart SCCM service (Only if the Intune service is available on your computer) Restart Intune Service (Only if the Intune service is available on your computer) Quick scan with Windows Defender Full Scan with Windows Defender Logs All actions are logged to C:\Tools_CCMTune\Logs Convert to EXE For converting this script to exe file, I recommend that you use the tool made available by Damien Van Robaeys Github Link :  https://github.com/damienvanrobaeys/PS1-To-EXE-Generator/tree/master/New_Version/Sources Website Link :  https://www.syst...

Check if your computer is Windows 11 compatible with Powershell

Image
Presentation This script allows you to have a first glimpse of the compatibility of your computer with Windows 11.  It was built on the basis of information available at the following address  https://www.microsoft.com/en-US/windows/windows-11-specifications Lien Github :   https://github.com/ChrisMogis/W11_PrerequisitesCkeck.ps1/blob/main/W11-PrerequisitesCheck.ps1 List of checked components : Architecture CPU RAM Screen resolution Hard drive Secure boot TPM version Script execution : The script must be run in a Powershell console with Admin rights .\W11_PrerequisitesCkeck.ps1 Results : If your computer is compatible Windows 11 : If your computer is not compatible Windows 11 :

Ping your infrastructure and send a desktop alert with Powershell

Image
Presentation This script runs and loads the contents of a file to recover a list of devices to ping. If the device does not respond, an alert is issued on the desktop. In addition, a log file containing the list of available perimeters is created in the C:Logs directory. Github link :   Script Script exécution powershell.exe -executionpolicy ByPass -file C:\Temp\PingInfra.ps1 Result For each computer that is not available, you received a desktop alert A log file is created to the repository C:\Logs folder

Manage Calendar Permissions on Office 365 with PowerShell

Image
This script is used to manage rights on users' calendars on Office 365 with Powershell. Github link :  Download Script Script exécution This script has three options for reading or changing rights on a user's calendar.  Command line : O365-ManageCalendarPermissions.ps1 -Choose Info Displays calendars and rights associated with the user's default calendar O365-ManageCalendarPermissions.ps1 -Choose Add Adds rights to a user in the organization on another user's calendar O365-ManageCalendarPermissions.ps1 -Choose Remove Remove rights to a user in the organization on another user's calendar Calendar permissions Exemple Add calendar permission 1. .\O365-ManageCalendarPermissions.ps1 -choose add 2. Enter your admin account information 3.  Enter verification code 4. Enter the name of the account to which you want to delegate a right 5. Enter the account name of the user to whom you want to assign rights 6. Specify permission type Result

Send email alert if Reboot or shutdown a Server with Powershell

Image
Présentation This script allows to send a status mail when a server restarts or stops. All actions are logged to C:\Logs. Github Link :  https://github.com/ChrisMogis/Scripts/blob/main/Alert_State_Server.ps1 Exécution command line for reboot status :  powershell.exe -executionpolicy ByPass -file .\ScriptName.ps1 -Option Reboot Exécution command line for shutdown status :  powershell.exe -executionpolicy ByPass -file .\ScriptName.ps1 -Option Shutdown #Script Parameters Param ( [Parameter(Mandatory= $true )] [ValidateSet( "Reboot" , "Shutdown" )] [String[]] $Option ) #Function create Log folder     Function CreateLogsFolder {     If (!( Test-Path C:\Logs))     {     New-Item -Force -Path "C:\Logs\" -ItemType Directory } else {     Write-Host "The folder " C:\Logs\ " already exists !"     } } #Create Log Folder     CreateLogsFolder #Declaration of script variables     ...

Monitor a server hard drives with Powershell

Image
Monitor a server hard drives with Powershell Script  This script is used to monitor the disk space of a server and to send an alert email when the remaining disk space reaches the limit set by the administrator. Github Link :  https://github.com/ChrisMogis/MonitoringFreeHardDriveSpace/blob/main/FreeSpaceHardDrive.ps1  #Function create Log folder     Function CreateLogsFolder {     If (!( Test-Path C:\Logs))     {     New-Item -Force -Path "C:\Logs\" -ItemType Directory } else {     Write-Host "The folder " C:\Logs\ " already exists !"     } } #Create Log Folder     CreateLogsFolder #Declaration of script variables $Client = "Client Name" $ListDisk = Get-CimInstance -Class Win32_LogicalDisk | where { $_ .DriveType -eq "3" } $Server = (Get-CimInstance -ClassName Win32_ComputerSystem).Name $SetMinSizeLimit = 50 GB; $LogPath = "C:\Logs\CheckHardDriveFreeSpace.log" $Date = Get-Date #Scan...