PowerShell - Module pour rajouter le service WDS

Windows Deployment Services ou WDS est une technologie de Microsoft qui va vous permettre  d'installer un système d'exploitation Windows via le réseau (PXE). Ils permettent d'installer à distance Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10, Windows Server 2008, Windows Server 2012 et Windows Server 2016 mais il est également possible de déployer d'autres systèmes d'exploitation Windows, en effet, le processus d'installation se fait à l'aide d'une image de type Windows Imaging Format (WIM) contrairement à RIS qui avait pour procédé l'automatisation de la phase d'installation du système d'exploitation. Il est ainsi possible d'installer des systèmes d'exploitation avec des applications préinstallées. WDS est un rôle optionnel qui est inclus dans toutes les éditions serveur de Windows depuis Windows Server 2008.

Pour utiliser ce script PowerShell, il faudra rajouter dans le paramètre le chemin du dossier à créer. Depuis Windows PowerShell, il faudra executer le script avec le chemin.
Exemple:
Installer le service Windows Deployment sur votre serveur et utiliser le repertoire C:\WDS.
PS-WDSUTIL.ps1 -RemInst C:\WDS
Retirer le service Windows Deployment sur votre serveur.
PS-WDSUTIL.ps1 -Remove

Voici le code au complet, si vous avez des problèmes merci de revenir vers moi, pour la correction.

<#
.SYNOPSIS
    Add or remove Windows Deployment Services for Windows Server.
.DESCRIPTION
    Add or remove Windows Deployment Services for Windows Server.
    PS-WDSUTIL take string for define the folder use for initialize server.
.PARAMETER Name
    
.EXAMPLE

PS-WDSUTIL.ps1 -RemInst C:\WDS
Initialize Windows Deployment Service on server and use C:\WDS folder

.EXAMPLE

PS-WDSUTIL.ps1 -Remove
Uninitialize Windows Deployment Service on server

.NOTES
Script Version 1.0
Tested on:  Windows Server 2016
            Windows Server 2016   
            
.LINK
https://tdelacour.wordpress.com/
#>

# Script Parameter

    param(
    [Parameter(Mandatory = $True)]
    [ValidateNotNullOrEmpty()]
    [string]$RemInst,
    [Parameter(Mandatory = $False)]
    [switch]$Remove
    )

#---------------------------------------------------

#region ProductType
# Get ProductType to define the type of the operating system
Try
{
    # Get information via Cim
    $OSQUERY = Get-CimInstance -Namespace ROOT/cimv2 -ClassName Win32_OperatingSystem
}
Catch
{
    # if Get-CimInstance not work, get information via Wmi
    $OSQUERY = Get-WmiObject  -Namespace ROOT/cimv2 -Class Win32_OperatingSystem
}

# Detection if the script uses on a server
if ($OSQUERY.ProductType -ne "3"){
Write-Output "This script, it's only for a Windows Server"
Write-Output "This script don't be used on Domain Controler"
Break
}

#endregion

# Check if Windows Deployment Service already exists

$WDSService = get-service -Name WDSServer

#If the Windows Deployment service is on its way, we will ask you the question if we withdraw the service

If(($($WDSService.Status) -eq $null -or $($WDSService.Status) -eq "Stopped") -eq $false){
    Write-Output "Would do you remove WDS Service ? (Default is No)"
    $ReadHost = Read-Host " ( Y / N ) "
    Switch ( $ReadHost ) {
    Y {Write-Output "Yes, Remove WDS Service"; $RemoveWDS=$true}
    N {Write-Output "No, Keep WDS Service"; $RemoveWDS=$false}
    Default {Write-Output "Default, Keep WDS Service"; $RemoveWDS=$false}
    }
    if($RemoveWDS -eq $true){
    wdsutil /verbose /Uninitialize-server
    }
    else
    {
    Write-output "Sorry, this script do nothing"
    Break
    }
}

#endregion
 
# Remove the folder to use by the script, if it already exists, with prompt

If((Test-Path $RemInst) -eq $true)
{
Write-Error "This folder already exist"
Remove-Item -Path $RemInst -Force -Recurse -Confirm
If((Test-Path $RemInst) -eq $true)
    {
        Write-Error "The folder is always present"
        Break
    }
}

#endregion

#region WindowsFeature

# Install Windows Feature wds-deployment
Try {
$ADDWDS = Install-WindowsFeature wds-deployment -IncludeManagementTools
$ADDWDS.ExitCode.value__
}
Catch
{
Write-Error $Error
}

If ($ADDWDS.ExitCode.value__ -eq "1003"){Write-Output "WDS Service is already install - No Change Needed"}

#endregion

#region CreateFolderReminst

# Create Reminst folder
New-Item -Path $RemInst -Force -ItemType directory

#endregion

#region InstallServic

# Detect if you computer is on domain or workgroup via cim or wmi
Try
{
    # Get information via Cim
    # PartOfDomain (boolean Property)
    $PartOfDomain = Get-CimInstance -Namespace ROOT/cimv2 -ClassName Win32_ComputerSystem | Select PartOfDomain | ft -AutoSize -HideTableHeaders
    # WorkGroup (String Property)
    $WorkGroup = Get-CimInstance -Namespace ROOT/cimv2 -ClassName Win32_ComputerSystem | select Workgroup | ft -AutoSize -HideTableHeaders
}
Catch
{
    # if Get-CimInstance not work, get information via Wmi
    # PartOfDomain (boolean Property)
    $PartOfDomain = (Get-WmiObject -Class Win32_ComputerSystem -Namespace ROOT/cimv2) | select PartOfDomain | ft -AutoSize -HideTableHeaders
    # WorkGroup (String Property)
    $WorkGroup = (Get-WmiObject -Class Win32_ComputerSystem -Namespace ROOT/cimv2) | select Workgroup | ft -AutoSize -HideTableHeaders
}

# Run WDSUTIL with the right settings, which depends on whether the server has on domain or not

if (!$PartOfDomain)
{
    Write-Output "Domain"
    WDSUTIL /Verbose /Progress /initialize-server /remInst:$RemInst
}
Else
{
if (!$WorkGroup)
    {
        Write-Output "Error Wmi\Cim filter"
        break
    }
    Else
    {
    Write-Output "Workgroup"
    WDSUTIL /Verbose /Progress /Initialize-Server /REMINST:$RemInst /Standalone
    }
}

#endregion

Commentaires

  1. Casino Games - JTR Hub
    Enjoy 전라남도 출장마사지 Casino Games - Play 샌즈 & win free spins for fun - No download & 영천 출장샵 No registration 공주 출장샵 required - Just get straight to playing! ✓Mobile Friendly Version. New 대전광역 출장샵

    RépondreSupprimer

Enregistrer un commentaire

Posts les plus consultés de ce blog

Powershell - Supprimer Teams sur l'ensemble des profils utilisateurs

Powershell - Comment tester les ports TCP ?

MRemoteNG - Voir les mots de passe dans l'application