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

relaunch from a specified point in case of error in my script

$
0
0

Hello, i have an issue, i would like to relaunch  my script from a specified point.

In my script people try to put an UNC , if this UNC  \"\server\share " is wrong. i want my script detect it and i would like to relaunch from the point to ask UNC again.

i try trap command to hide the error message , and it show the error BUT i d'ont know how to relaunch from the asking of share

At the end of this script:

$ErrorActionPreference = 'silentlycontinue'
trap {"Vous n'avez pas donner le bon partage";continue}

SCRIPT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

CLEAR

Write-Host "`n`nBienvenue sur Tim ACL" -ForegroundColor Yellow

$Domain = Read-Host "PUT YOUR DOMAIN"

$UNC = read-host "PUT YOUR SHARE"

if ($Domain -eq "HO")

{


#Connexion à l'ACL sur le serveur#
$Drive = "B:"

# IF THE DRIVE DOESN 't EXIST

      
if (((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive}))

# vrai , supprime
{
       
$net = $(New-Object -comobject WScript.Network)
$net.RemoveNetworkDrive($Drive,1)
      
}
# IF EXIST

if (!((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive}))
              
{

# Création objet , et map drive
$net = $(New-Object -comobject WScript.Network)
$net.mapnetworkdrive("$Drive","$Unc",$false, "ho\fr497199", "Devoteam.2017")
$ErrorActionPreference = 'silentlycontinue'
trap {"YOU DIDNT GIV THE CORRECT SHARE";continue}

CLEAR

Write-Host "`n`nBienvenue sur Tim ACL" -ForegroundColor Yellow

$Domain = Read-Host "Veuillez entrer le domaine sans extension"

$UNC = read-host "Veuillez entrer le nom de votre partage"

if ($Domain -eq "HO")

{


#Connexion à l'ACL sur le serveur#
$Drive = "B:"

# Si le drive existe alors supprime.
      
if (((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive}))

# vrai , supprime
{
       
$net = $(New-Object -comobject WScript.Network)
$net.RemoveNetworkDrive($Drive,1)
      
}
# Si n'existe pas
if (!((New-Object -Com WScript.Network).EnumNetworkDrives() | Where-Object `
{$_ -eq $Drive}))
              
{

# Création objet , et map drive
$net = $(New-Object -comobject WScript.Network)
$net.mapnetworkdrive("$Drive","$Unc",$false, "ho\fr497199", "Devoteam.2017")
$ErrorActionPreference = 'silentlycontinue'
trap {"Vous n'avez pas donner le bon partage";continue}


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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