Question Récupération d'infos sur poste distant

Plus d'informations
il y a 3 ans 5 mois - il y a 3 ans 5 mois #30111 par Rigollet
Bonjour,

J'ai récupéré ce script sur le net qui fonctionne bien en local mais pas lorsque je souhaite l'utiliser sur les postes distants de notre domaine d'entreprise. Mon ordinateur est admin et appartient pourtant à ce domaine.
J'obtiens ce type de message d'erreur (couleur rouge). Pouvez vous m'aider, merci ?

PS C:\Users\HBI-PARIG\Documents\Logiciels\Scripts> .\Get-PCInfo.ps1 -Computer desktop-cperr
Get-WmiObject : Accès refusé.
Au caractère C:\Users\HBI-PARIG\Documents\Logiciels\Scripts\Get-PCInfo.ps1:36 : 18
+ ... omputerHW = Get-WmiObject -Class Win32_ComputerSystem -Computername $ ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
+ FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

<#
.SYNOPSIS
Name: Get-PCInfo.ps1
The purpose of this script is to retrieve basic information of a PC.

.DESCRIPTION
This is a simple script to retrieve basic information of domain joined computers.
It will gather hardware specifications and Operating System and present them on the screen.

.RELATED LINKS
www.sconstantinou.com

.PARAMETER Computer
This is the only parameter that is needed to provide the name of the computer either
in as computer name or DNS name.

.NOTES
Updated: 08-02-2018 Testing the connection before the information gathering.
Release Date: 05-02-2018

Author: Stephanos Constantinou

.EXAMPLE
Run the Get-PCInfo script to retrievw the information.
Get-PCInfo.ps1 -Computer test-pc
#>

Param(
[string]$Computer
)

$Connection = Test-Connection $Computer -Count 1 -Quiet

if ($Connection -eq "True"){

$ComputerHW = Get-WmiObject -Class Win32_ComputerSystem -Computername $Computer | select Manufacturer,Model | FT -AutoSize

$ComputerCPU = Get-WmiObject win32_processor -ComputerName $Computer | select DeviceID,Name | FT -AutoSize

$ComputerOS = Get-WmiObject -Class Win32_BIOS -NameSpace "root\CIMV2" -ComputerName $Computer | select SerialNumber | FT -AutoSize

$colItems = Get-WmiObject -class "Win32_NetworkAdapterConfiguration" -Computername $Computer | Where{$_.IpEnabled -Match "True"}

$ComputerDisks = Get-WmiObject -Class Win32_LogicalDisk -Filter "DriveType=3" -ComputerName $Computer | select DeviceID,VolumeName,Size,FreeSpace | FT -AutoSize

switch -Wildcard ($ComputerOS){
"6.1.7600" {$OS = "Windows 7"; break}
"6.1.7601" {$OS = "Windows 7 SP1"; break}
"6.2.9200" {$OS = "Windows 8"; break}
"6.3.9600" {$OS = "Windows 8.1"; break}
"10.0.*" {$OS = "Windows 10"; break}
default {$OS = "Unknown Operating System"; break}
}

Write-Host "Computer Name: $Computer"
Write-Host "Operating System: $OS"
Write-Output $ComputerHW
Write-Output $ComputerCPU
Write-Output $ComputerOS
Write-Output $colItems
Write-Output $ConsoleFileName
Write-Output $ComputerDisks

}
else {
Write-Host -ForegroundColor Red @"

Computer is not reachable or does not exists.

"@
}
Dernière édition: il y a 3 ans 5 mois par Rigollet.

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

Plus d'informations
il y a 3 ans 5 mois #30112 par Laurent Dardenne
A priori pb de droits sur le distant. Recherche sur Google 'get-wmi remote UnauthorizedAccessException'

Tutoriels PowerShell
Les utilisateur(s) suivant ont remercié: Rigollet

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

Plus d'informations
il y a 3 ans 4 mois #30148 par Philippe
salut PRIG0LL3T et Laurent

il faut que tu utilise pour exécuter ton script un compte administrateur du domaine
apres comme dis Laurent il faudra peut être les autorisations WMI à distance, regarde docs.microsoft.com/fr-fr/dotnet/framewor.../diagnostics/wmi/ici

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

Plus d'informations
il y a 3 ans 4 mois #30160 par PatriceLT
Bonjour,

Pourquoi ne pas directement utiliser "Invoke-Command" ? ça serait peut être plus simple non ?

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

Plus d'informations
il y a 3 ans 4 mois #30166 par Philippe
bonjour PatriceLT

tu a raison c'est souvent plus simple d'utiliser "Invoke-Command", mais le problème de droits restera quand même
il faut d'abord résoudre ce problème avant de penser à l'amélioration ;)

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

Plus d'informations
il y a 3 ans 4 mois #30167 par PatriceLT
Effectivement. Les droits doivent pas être normalement admin local de la machine? Pour les admins domaines, c'est rarement utilisés, enfin un compte admin du domaine via un get credential effectivement serait le must.

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

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