IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Scripts/Batch Discussion :

Utilisation de plusieurs pages ps1 [PowerShell]


Sujet :

Scripts/Batch

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti Avatar de botLIA
    Homme Profil pro
    Étudiant en Licence 3 CDA
    Inscrit en
    Juin 2016
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Étudiant en Licence 3 CDA
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2016
    Messages : 45
    Par défaut Utilisation de plusieurs pages ps1
    Bonjour,

    Je suis sur un projet en PowerShell et j'ai un premier fichier ps1 qui est mon programme principal, j'ai un second fichier ps1 qui contient une Class pour créer un objet Salarié,
    comment je peut faire le lien entre les deux fichiers pour pouvoir utilisé la Class dans mon programme principal pour créer l'objet ?

    Cordialement.

  2. #2
    Rédacteur


    Profil pro
    Inscrit en
    Janvier 2003
    Messages
    7 171
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2003
    Messages : 7 171
    Billets dans le blog
    1
    Par défaut
    Salut,
    utilise le dot source sur ton fichier . .\NewMaclasse.ps1.

  3. #3
    Membre averti Avatar de botLIA
    Homme Profil pro
    Étudiant en Licence 3 CDA
    Inscrit en
    Juin 2016
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Étudiant en Licence 3 CDA
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2016
    Messages : 45
    Par défaut
    Salut,

    Pour que ce soit plus explicite voila mon fichier script qui est mon programme principale :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
                            #############################
                            #    Programme Principal    # 
                            #############################
    
        ############################################
        #    Vérification des fichiers RH et AD    #
        ############################################
    
    # Instantiation d'un Objet Excel pour le fichier RH.
    # Rend non visible à l'écran la fenêtre Excel.
    # Désactive les messages d'alertes.
    
    $excelRh = New-Object -ComObject Excel.Application
    $excelRh.Visible = $true
    $excelRh.DisplayAlerts = $false
    $workbookRh = $excelRh.Workbooks.Open("C:\Users\ltanne\Desktop\preprod\fichierRH\Etat_DSI_MAI_2018.xlsx")
    $worksheetRh = $workbookRh.Worksheets.item("Feuil1")
    $worksheetRh.Activate()
    
    # Déclaration et instantiations des variables ligne et colonne de la feuille
    $ligne = 3
    $colonne = 1
    
    # Test de la création d'un Salarié à l'aide de la Class SalarieRh
    Set-Location "C:\Users\ltanne\Desktop\preprod\script"
    .\salarie.ps1
    [SalarieRh] $salarie = [SalarieRh]::new($ligne, $colonne)
    Write-Host($salarieRh.ToString)
    
    #foreach( $lignes in $ligne ){
    #    foreach( $colonnes in $colonne ){
    #        $salarieRh = [SalarieRh]::new()
    #    }
    #}
    Et voila mon autre fichier script avec ma class :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    Class SalarieRh
    {
        # Propriétés
        [string] $matriculeRh
        [string] $nomRh
        [string] $prenomRh
        [string] $nomPrenomRh
        [string] $qualificationRh
        [string] $numServiceRh
        [string] $serviceRh
    
        # Constructeur
        SalarieRh([string] $ligne, [string] $colonne){
    
            # Ouverture du fichier RH
            $excel = New-Object -ComObject Excel.Application
            $excel.Visible = $true
            $excel.DisplayAlerts = $false
            $workbook = $excel.Workbook.open("../fichierRH/*")
            $worksheet = $workbook.Worksheets.item("Feuil1")
            $worksheet.Activate()
    
            # Instanciation des propriétés
            $this.matricule = $worksheet.Cells.Item($ligne, $colonne).Value()
            $this.nomRh = $worksheet.Cells.Item($ligne, ($colonne + 1)).Value()
            $this.prenomRh = $worksheet.Cells.Item($ligne, ($colonne + 2)).Value()
            $this.nomPrenomRh = $worksheet.Cells.Item($ligne, ($colonne + 3)).Value()
            $this.qualificationRh = $worksheet.Cells.Item($ligne, ($colonne + 5)).Value()
            $this.numServiceRh = $worksheet.Cells.Item($ligne, ($colonne + 6)).Value()
            $this.serviceRh = $worksheet.Cells.Item($ligne, ($colonne + 7)).Value()
    
            # Fermeture du fichier RH
            $excel.Quit()
        }
    
        # Accesseurs
        [string] GetMatriculeRh($matriculeRh){
            return $matriculeRh
        }
    
        [string] GetNomRh($nomRh){
            return $nomRh
        }
    
        [string] GetPrenomRh($prenomRh){
            return $prenomRh
        }
    
        [string] GetNomPrenomRh($nomPrenomRh){
            return $nomPrenomRh 
        }
    
        [string] GetQualificationRh($qualificationRh){
            return $qualificationRh
        }
    
        [string] GetNumService($numServiceRh){
            return $numServiceRh
        }
    
        [string] GetServiceRh($serviceRh){
            return $serviceRh
        }
    
        [string] ToString($matriculeRh, $nomRh, $prenomRh, $nomPrenomRh, $qualificationRh, $numServiceRh, $serviceRh){
            return "Salarié : Matricule = " + $matriculeRh + " ; Nom = " + $nomRh + " ; Prénom = " + $prenomRh + " ; NomPrénom = " + $nomPrenomRh + " ; Qualification = " + $qualificationRh + " ; numéroService = " + $numServiceRh + " ; Service = " + $serviceRh
        }
    }
    Il me dit qu'il ne trouve pas [SalarieRh] dans [SalarieRh]::new($, $) dans mon programme principal.

  4. #4
    Membre averti Avatar de botLIA
    Homme Profil pro
    Étudiant en Licence 3 CDA
    Inscrit en
    Juin 2016
    Messages
    45
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Étudiant en Licence 3 CDA
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2016
    Messages : 45
    Par défaut
    Enfaite c'est bon j'ai relu mon code et je me suis rendu compte qu'il étais trop obscure du coup je l'ai réécris et il fonctionne

    Merci quand même.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. conserver données à utiliser pour plusieurs pages
    Par mikoumed dans le forum Langage
    Réponses: 15
    Dernier message: 28/12/2011, 19h50
  2. Réponses: 5
    Dernier message: 25/11/2008, 10h41
  3. Réponses: 4
    Dernier message: 23/01/2008, 16h46
  4. utiliser un menu unique pour plusieurs pages...
    Par brouette dans le forum ActionScript 1 & ActionScript 2
    Réponses: 8
    Dernier message: 17/12/2006, 01h29
  5. Variable utilisée ds plusieurs pages asp
    Par zorba49 dans le forum ASP
    Réponses: 3
    Dernier message: 26/05/2005, 15h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo