Question
identifiant OS
- VOISIN
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 6 ans 3 mois #24801
par VOISIN
identifiant OS a été créé par VOISIN
Bonjour,
Je suis en cours de création d'un script d'installation du service SNMP et je cherche à faire une vérification de la version d'OS pour appliquer la bonne commande d'installation.
je suis parti sur ce type de script mais ça ne fonctionne pas :
$ver = Get-WmiObject Win32_OperatingSystem | Select-Object version
if ($ver.version -lt 6)
{
if ($ver.version -lt 6.3)
{
$check = Get-WindowsFeature -Name SNMP-Services
If ($check.Installed -ne \"True\")
{
#Install/Enable SNMP-Service
Write-Host \"SNMP Service Installing...\"
Get-WindowsFeature -name SNMP* | Add-WindowsFeature | Out-Null
Write-Host \"Windows 2008 SNMP Service Installed !!\" -foregroundcolor \"Green\"
}
Else
{
Write-Host \"Windows 2008 SNMP Service Déjà Installed !!\" -foregroundcolor \"Blue\"
}
Else
{ $check = Get-WindowsFeature -Name SNMP-Services
If ($check.Installed -ne \"True\")
{
#Install/Enable SNMP-Service
Write-Host \"SNMP Service Installing...\"
Get-WindowsFeature -Name *snmp* | Install-WindowsFeature | Out-file
Write-Host \"Windows 2012/2016 SNMP Service Installed !!\" -foregroundcolor \"Green\"
}
Write-Host \"Windows 2012/2016 SNMP Service Déjà Installed !!\" -foregroundcolor \"Blue\"
{
}
Else
{
Write-Host Serveur en Windows 2003 à configurer manuellement -foregroundcolor \"red\"
}
}
}
}
Je suis en cours de création d'un script d'installation du service SNMP et je cherche à faire une vérification de la version d'OS pour appliquer la bonne commande d'installation.
je suis parti sur ce type de script mais ça ne fonctionne pas :
$ver = Get-WmiObject Win32_OperatingSystem | Select-Object version
if ($ver.version -lt 6)
{
if ($ver.version -lt 6.3)
{
$check = Get-WindowsFeature -Name SNMP-Services
If ($check.Installed -ne \"True\")
{
#Install/Enable SNMP-Service
Write-Host \"SNMP Service Installing...\"
Get-WindowsFeature -name SNMP* | Add-WindowsFeature | Out-Null
Write-Host \"Windows 2008 SNMP Service Installed !!\" -foregroundcolor \"Green\"
}
Else
{
Write-Host \"Windows 2008 SNMP Service Déjà Installed !!\" -foregroundcolor \"Blue\"
}
Else
{ $check = Get-WindowsFeature -Name SNMP-Services
If ($check.Installed -ne \"True\")
{
#Install/Enable SNMP-Service
Write-Host \"SNMP Service Installing...\"
Get-WindowsFeature -Name *snmp* | Install-WindowsFeature | Out-file
Write-Host \"Windows 2012/2016 SNMP Service Installed !!\" -foregroundcolor \"Green\"
}
Write-Host \"Windows 2012/2016 SNMP Service Déjà Installed !!\" -foregroundcolor \"Blue\"
{
}
Else
{
Write-Host Serveur en Windows 2003 à configurer manuellement -foregroundcolor \"red\"
}
}
}
}
Connexion ou Créer un compte pour participer à la conversation.
- crogiez
- Hors Ligne
- Membre premium
Réduire
Plus d'informations
- Messages : 102
- Remerciements reçus 0
il y a 6 ans 3 mois #24819
par crogiez
Réponse de crogiez sur le sujet Re:identifiant OS
bonjour et bonne année 2018
PS C:\> $ver.GetType()
IsPublic IsSerial Name BaseType
----
True False PSCustomObject System.Object
$ver est un type pscustomobject
pas un nombre, ni une chaine
PS C:\> $ver.ToString() -gt \"6\"
False
encore raté !!!
PS C:\> $ver.version -eq \"6.1.7601\"
True
PS C:\> $ver.version.Substring(0,1) -eq \"6\"
True
PS C:\> $ver.version.Substring(0,3) -eq \"6.1\"
True
il faut indenté ton programme
[code:1]
PS C:\Users\admex_crogiez> $ver = Get-WmiObject Win32_OperatingSystem | Select-Object version
if ($ver.version.Substring(0,1) -eq \"6\"«»)
{
\"on est en version 6\"
if ($ver.version.Substring(0,3) -eq \"6.1\"«»)
{
\"on est en verion 6.1\"
}
}
on est en version 6
on est en verion 6.1
[/code:1]
t'as compris ?????????
bisoux
Message édité par: crogiez, à: 10/01/18 16:13
Message édité par: crogiez, à: 10/01/18 16:14<br><br>Message édité par: crogiez, à: 10/01/18 16:21
PS C:\> $ver.GetType()
IsPublic IsSerial Name BaseType
----
True False PSCustomObject System.Object
$ver est un type pscustomobject
pas un nombre, ni une chaine
PS C:\> $ver.ToString() -gt \"6\"
False
encore raté !!!
PS C:\> $ver.version -eq \"6.1.7601\"
True
PS C:\> $ver.version.Substring(0,1) -eq \"6\"
True
PS C:\> $ver.version.Substring(0,3) -eq \"6.1\"
True
il faut indenté ton programme
[code:1]
PS C:\Users\admex_crogiez> $ver = Get-WmiObject Win32_OperatingSystem | Select-Object version
if ($ver.version.Substring(0,1) -eq \"6\"«»)
{
\"on est en version 6\"
if ($ver.version.Substring(0,3) -eq \"6.1\"«»)
{
\"on est en verion 6.1\"
}
}
on est en version 6
on est en verion 6.1
[/code:1]
t'as compris ?????????
bisoux
Message édité par: crogiez, à: 10/01/18 16:13
Message édité par: crogiez, à: 10/01/18 16:14<br><br>Message édité par: crogiez, à: 10/01/18 16:21
Connexion ou Créer un compte pour participer à la conversation.
- VOISIN
- Auteur du sujet
- Hors Ligne
- Nouveau membre
Réduire
Plus d'informations
- Messages : 4
- Remerciements reçus 0
il y a 6 ans 3 mois #24866
par VOISIN
Réponse de VOISIN sur le sujet Re:identifiant OS
crogiez - Merci c'est le bout qui me manquait effectivement!!
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.064 secondes
- Vous êtes ici :
- Accueil
- forum
- PowerShell
- Entraide pour les débutants
- identifiant OS