I just set up a script to provide all the information of a computer (see script). the script works very well, it goes back all the information of the machine (IP) when it is a question of executing it on a desktop. For remote users (laptop) use a 3G chip finally to connect via VPN on the network of our company, the script goes back the IP of the 3G chip. the goal is to make sure when using the VPN, the script must return the IP of the VPN and not that of 3G.
after several tests, I can not do it. could you help me ?
thank you
Code: Select all
Add-Type -AssemblyName presentationframework
Add-Type -AssemblyName PresentationCore
Add-Type -AssemblyName WindowsBase
#[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
#Chargement de la vue
$XamlLoader = (New-Object System.Xml.XmlDocument)
$XamlLoader.Load((get-location).path + "\layout.xaml")
$XamlMainWindow = $XamlLoader
$Reader = (New-Object System.Xml.XmlNodeReader $XamlMainWindow)
$Form = [Windows.Marku[Codebox=powershell file=Untitled.ps1]p[/Codebox].XamlReader]::Load($Reader)
#Nom de l'ordinateur
$computerName = $Form.findname("computerName")
$computerName.Content = $env:computername
#Adresses IP
$ip1 = $Form.findname("ip1")
$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.IPAddress -ne $null})
$ip1.Content = $(($ip | select-object -first 1).ipaddress[0])
#Passerelle
$ip = (Get-WmiObject -Class Win32_NetworkAdapterConfiguration | Where {$_.IPAddress -ne $null})
$gateway = $Form.findname('gateway')
$gateway.Content = $(($ip | select-object -first 1).DefaultIpGateway[0])
#Adresses MAC
$mac1 = $Form.findname('mac1')
# $mac2Txt = $Form.findname('mac2')
$mac=(Get-WmiObject win32_networkadapterconfiguration | select macaddress | where {$_.macaddress -ne $null})
#SLE/Debug $mac1 = $mac[0].macaddress
# $mac2 = $mac[1].macaddress
#SLE/Debug $mac1.Content = $mac1
$mac1.Content = $mac[0].macaddress
# $mac2Txt.Text = $mac2
#Domaine
$domain = $Form.findname('domain')
$domain.Content = $env:USERDOMAIN
#Serveur de connexion
$coServer = $form.findname('coServer')
$coServer.Content = $env:logonserver
#Version système d'exploitation
$osVersionTxt = $Form.findname('os')
$os = Get-WmiObject -class Win32_OperatingSystem
$osName=$os.Caption
$osSp=$os.ServicePackMajorVersion
#SLE/Debug $os.Content = $osName + ' Service Pack ' + $osSp
$osVersionTxt.Content = $osName + ' Service Pack ' + $osSp
#Numéro série PC
$pcSerial = $Form.findname('pcSerial')
$pcSerial.Content = (gwmi win32_bios).serialnumber
#Version internet explorer
$ieVersion = $Form.findname('ieVersion')
$ieVersion.Content = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet Explorer').svcVersion
#Utilisateur connecté localement
$user = $Form.findname('user')
$user.Content = $env:UserName
#Dernier boot
$lastBoot = $Form.findname('lastBoot')
$date=Get-WmiObject win32_operatingsystem | select csname, @{LABEL=’LastBootUpTime’;EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}
$lastBoot.Content = $date.lastbootuptime
#Mémoire physique
$memory = $Form.findname('memory')
$bytes = (Get-WmiObject -class "cim_physicalmemory" | Measure-Object -Property Capacity -Sum).Sum
$mb = $bytes / 1024 / 1024
$mb =
$memory.Content = $mb.tostring() + ' MB'
#Espace libre disques durs
$hdd = $Form.findname('hdd')
$disk = Get-WmiObject Win32_LogicalDisk -Filter "DeviceID='C:'" | Select-Object FreeSpace
$freeSpace = [Math]::Round($Disk.Freespace / 1GB, 2)
$hddFormat = (GET-WMIOBJECT -query "select * from win32_logicaldisk where drivetype =3" | select *).filesystem
$hddName = (GET-WMIOBJECT -query "select * from win32_logicaldisk where drivetype =3" | select *).caption
$hdd.Content = $hddName + '\ ' + $freeSpace + ' GB ' + $hddFormat
#Numéro de la hotline
$hotline = $Form.findname('hotline')
$hotline.Content = '01 69 93 11 76'
#Modèle du PC
$model = $Form.findname('model')
$infosPC = Get-CimInstance -ClassName Win32_ComputerSystem
$model.content = $infosPC.Model
$Form.ShowDialog() | out-null