<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; PowerShell вывод имен операционных систем]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=11156&amp;type=atom" />
	<updated>2015-12-18T14:53:06Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=11156</id>
		<entry>
			<title type="html"><![CDATA[PowerShell вывод имен операционных систем]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=99750#p99750" />
			<content type="html"><![CDATA[<p>Добрый вечер. Помогите разобраться (PowerShell стал изучать не давно).</p><p>По заданию в файле Spisok.txt находится список имен компьютеров, нужно их опросить и вывести название операционных систем. <br /></p><div class="codebox"><pre><code>
    ..........................
    $ishod = &quot;Microsoft Windows 7 Профессиональная&quot;  
    try{   
            $ser = Get-Content C:\t\Spisok.txt
            $os  = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $ser
            foreach ($sProperties in $os)
            {  
                $val=$sProperties.Caption         
                $val = $val -replace $val, $ishod #имя ОС
                if($val -eq $ishod)
                {      
                    Write-Host $sProperties.__SERVER &quot;-&quot; $val -ForegroundColor Green
                }   
            }
       }
    catch [System.UnauthorizedAccessException]
    {
          Write-Host &quot;Ошибка&quot;
    }</code></pre></div><p>Он работает (без try catch) только в том случае, если компьютер при проверки включен.<br />А как это обойти???</p><p>Выводит ошибку:<br />Get-WmiObject : Сервер RPC недоступен. (Исключение из HRESULT: 0x800706BA)<br />строка:26 знак:22<br />+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$os&nbsp; = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $s ...<br />+&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />&nbsp; &nbsp; + CategoryInfo&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : InvalidOperation: (:) [Get-WmiObject], COMException<br />&nbsp; &nbsp; + FullyQualifiedErrorId : GetWMICOMException,Microsoft.PowerShell.Commands.GetWmiObjectCommand</p>]]></content>
			<author>
				<name><![CDATA[Dark_Evans]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33550</uri>
			</author>
			<updated>2015-12-18T14:53:06Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=99750#p99750</id>
		</entry>
</feed>
