Question Ne pas afficher certains résultats

Plus d'informations
il y a 2 ans 10 mois #30969 par Sebastien
Bonjour,
J'essaye de poursuivre mon petit script sans prétention. Quelques petits trucs a régler mais pour un premier script, je suis satisfait.
Bon mon script me met d'abord sur le bon réseau et en sortie m'affiche plein d'information dont je n'ai pas besoin. Je voudrais ne pas les afficher. J'ai alors tenter un bon vieux echo off des familles mais visiblement ca ne marche pas sur PS.
Voici mes commandes : 
Enable-NetAdapter -Name Ethernet -Confirm:$false
#Désactive la carte Wi-Fi
Disable-NetAdapter -Name Wi-Fi -Confirm:$false
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.6.195.159 -PrefixLength "24" -defaultGateway 10.6.195.1
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses "10.6.195.1,8.8.8.8"
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyServer -Value "10.6.195.1:3128"
Set-ItemProperty -Path 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' -name ProxyEnable -Value 1

Voici le retour affiché :
IPAddress         : 10.6.195.159
InterfaceIndex    : 18
InterfaceAlias    : Ethernet
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Tentative
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : ActiveStore

IPAddress         : 10.6.195.159
InterfaceIndex    : 18
InterfaceAlias    : Ethernet
AddressFamily     : IPv4
Type              : Unicast
PrefixLength      : 24
PrefixOrigin      : Manual
SuffixOrigin      : Manual
AddressState      : Invalid
ValidLifetime     : Infinite ([TimeSpan]::MaxValue)
PreferredLifetime : Infinite ([TimeSpan]::MaxValue)
SkipAsSource      : False
PolicyStore       : PersistentStore

Comment ne pas faire apparaitre ces résultats svp ?

Merci

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 ans 10 mois #30970 par Arnaud Petitjean
Bonjour Sébastien,

Pour masquer le résultat d'une commande, tu peux au choix utiliser les techniques suivantes : 
# 1ere option - Stocker dans une variable le résultat et ne jamais retourner la variable
$myVar = New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.6.195.159 -PrefixLength "24" -defaultGateway 10.6.195.1

# 2e option - Stocker le retour dans la variable $null
$null = New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.6.195.159 -PrefixLength "24" -defaultGateway 10.6.195.1

#3e option - Rediriger le résultat vers la commande Out-Null
New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.6.195.159 -PrefixLength "24" -defaultGateway 10.6.195.1 | Out-Null

Il existe encore beaucoup d'autres techniques mais je ne pense pas que ce soit utile de toutes les connaître ;-)

Arnaud

MVP PowerShell et créateur de ce magnifique forum :-)
Auteur de 6 livres PowerShell aux éditions ENI
Fondateur de la société Start-Scripting
Besoin d'une formation PowerShell ?

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 ans 10 mois #30971 par Sebastien
Merci beaucoup pour ton aide, j'ai opté pour la solution 3 (j'ai un peu de mal avec la notion de variable encore) mais elle fonctionne
Problème suivant !

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 2 ans 10 mois #30976 par ericlm128
une 4eme pour compléter
[void]New-NetIPAddress -InterfaceAlias "Ethernet" -IPAddress 10.6.195.159 -PrefixLength "24" -defaultGateway 10.6.195.1
Les utilisateur(s) suivant ont remercié: Arnaud Petitjean

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.087 secondes
Propulsé par Kunena