我有一个小脚本来获取有关我域中网络计算机的信息,但在执行过程中脚本省略了两行。
$HostName = Read-Host 'Veuillez donner le nom du poste que vous voulez verifier?'
If (Test-Connection $HostName -count 4 -quiet)
{
Write 'The host responded';
gwmi win32_volume -ComputerName $HostName -Filter 'drivetype = 3' | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)} };
Get-WmiObject Win32_OperatingSystem -ComputerName $HostName | Select-Object PSComputerName, Description, OSArchitecture;
Get-ADComputer $HostName | select DistinguishedName;
Get-WmiObject -Class Win32_Product -Computer $HostName | Format-Table -Property Name, Version, InstallDate, Vendor;
}
else
{
Write 'The host doesn''t responded';
}
问题似乎不在命令中(我通过直接在控制台中键入它来获得所需的结果),但是在命令的位置。
我试图颠倒命令的顺序,结果总是如下:
if
声明之后:
我也尝试过这样:
If (Test-Connection $HostName -count 4 -quiet)
{
Get-WmiObject Win32_OperatingSystem -ComputerName $HostName | Select-Object PSComputerName, Description, OSArchitecture;
Get-ADComputer $HostName | select DistinguishedName;
Get-ADComputer $HostName | select DistinguishedName;
Get-WmiObject Win32_OperatingSystem -ComputerName $HostName | Select-Object PSComputerName, Description, OSArchitecture;
Get-ADComputer $HostName | select DistinguishedName;
Write 'The host responded';
gwmi win32_volume -ComputerName $HostName -Filter 'drivetype = 3' | select driveletter, label, @{LABEL='GBfreespace';EXPRESSION={"{0:N2}" -f ($_.freespace/1GB)} };
Get-WmiObject -Class Win32_Product -Computer $HostName | Format-Table -Property Name, Version, InstallDate, Vendor;
}
if
声明之后: