Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

a question to loop a variables in other variable

$
0
0

hello,

i want to loop my variables to my request in my script below , i notified my request at the end and whitch i want to loop for my different variables.

i dont want to do my request fo each servers but a solution to do this tasks efficiently with one loop

a solution ? 

# Recherche des tous controlleurs de domaines

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
$servers = $dom.DomainControllers

# Variable du chemin d'accès identiques a tous les serveurs
$Drive = "D$\Backup\FullBackup"

#Format de la date
$date = Get-Date -Format "MM-dd-yyyy"

#test d'existance du fichier de log
$TestPath = test-path -path "\\par1\d$\logs_backupsAD"


#Création du fichier de log si il n'existe pas
if ($TestPath -eq $False)
{
$logDirectory = New-Item -Path "\\par1-05\d$\logs_backupsAD"  -ItemType directory
$log = New-item -path "\\par1-05\d$\logs_backupsAD\log_ADSAVE_$date.txt" -type file
}

# mise en variable du fichier de log
$ServerReport = "\\par1\d$\logs_backupsAD\log_ADSAVE_$date.txt"


# Recherche des controlleurs que nous voulons récupérer en ajoutant le chemin de l'emplacement de la sauvegarde
foreach ($server in $servers)
{

$server = $server.name
$server = "\\$server\" + "$Drive"

if ($server -match \\ZRH)
{
$ZRHDC1 = $server
}


if ($server -match \\ZRH1)
{
$ZRHDC2 = $server
}

If ($server -match \\LON1)
{
$LON1DC1 = $server
}

If ($server -match \\LON2)
{
$LON1DC2 = $server
}

If ($server -match \\CGN1)
{
$CGN1DC1 = $server
}

If ($server -match \\fra1)
{
$fra1dc1 = $server
}

}

# Test et copie des dossiers de sauvegardes sur les controlleurs de domaines

#I WANT DO THIS LOOP HERE depending from variables defined before,

if ((Test-Path -Path $ZRH) -eq $True)
{
copy-item $ZRHDC1 -destination "$ZRHDC2\ADSAVE_ZRHDC1-01" -Recurse
Add-Content -Path $ServerReport -Value "Votre Backup pour le serveur ZRHDC1-01 a été effectuée vers le serveur $ZRHDC2\ADSAVE_ZRHD le $date"
}

 

 

 

 


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>