Oops.. didn't notice that, it seeped inside... sorry
-----
Shay Levi
$cript Fanatic
http://scriptolog.blogspot.com
Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
> How do I set get-wmiobject -erro?
>
> Thanks,
> Rey
> "Shay Levi" wrote:
>
>> Try to ping each machine before trying to query it:
>>
>> $server="google.com" # name or ip
>> $ping = new-object System.Net.NetworkInformation.Ping;
>> if($ping.Send($server)){
>> write-host "online"
>> } else {
>> write-host "offline"
>> }
>> Another option is to set get-wmiobject -erro
>> -----
>> Shay Levi
>> $cript Fanatic
>> http://scriptolog.blogspot.com
>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
>>> Thank you. I am getting a better understanding of how this logic
>>> works. I get an OK now for the systems that are online, but it does
>>> not display Needs Attention for the others which may be offline.
>>>
>>> Here's the error.
>>>
>>> Get-WmiObject : The RPC server is unavailable. (Exception from
>>> HRESULT:
>>> 0x800706BA)
>>> At C:\data\PSScripts\GetOSTypeFromAFileExportToExcel.ps1:17 char:24
>>> + $System = Get-WMIObject <<<< Win32_OperatingSystem -ComputerName
>>> $Machine
>>> Get-WmiObject : Invalid parameter
>>> At C:\data\PSScripts\GetOSTypeFromAFileExportToExcel.ps1:17 char:24
>>> + $System = Get-WMIObject <<<< Win32_OperatingSystem -ComputerName
>>> $Machine
>>> True
>>> Any suggestions?
>>> Thanks again for the education.
>>> Rey
>>> "Shay Levi" wrote:
>>>> Rey,
>>>>
>>>> If you want to test against a boolean variable ($path) for true or
>>>> false
>>>> use $true or $false.
>>>> If $path equels $true then you can write just:
>>>> If ($path){...} # evaluated to $true
>>>> Instead of:
>>>>
>>>> If ($path -eq $true){...}
>>>>
>>>> That said, you can rewrite the if/else :
>>>>
>>>> If ($path){
>>>> $Sheet.Cells.Item($intRow, 3).Interior.ColorIndex = 4
>>>> $Sheet.Cells.Item($intRow, 3) = "Good"
>>>> } else {
>>>> $Sheet.Cells.Item($intRow, 3).Interior.ColorIndex = 3
>>>> $Sheet.Cells.Item($intRow, 3) = "Needs Attention!"
>>>> }
>>>> -----
>>>> Shay Levi
>>>> $cript Fanatic
>>>> http://scriptolog.blogspot.com
>>>> Hebrew weblog: http://blogs.microsoft.co.il/blogs/scriptfanatic
>>>>> I have pieced together a small script to get the contents of a
>>>>> text file which includes several workstations. The result I am
>>>>> looking for is if the path to a particular file cannot be found,
>>>>> then mark as “Needs Attention” in Excel. If it is found, to mark
>>>>> as “OK”.Each time I run the script it imports correctly the
>>>>> systems that do have the file but it does not display the systems
>>>>> that do not or are possibly offline. Also, it never displays OK or
>>>>> Needs Attention. Can someone please enlighten my remedial
>>>>> powershell scripting?
>>>>>
>>>>> Thanks,
>>>>> Rey
>>>>> $Excel = New-Object -ComObject Excel.Application
>>>>> $Excel.visible = $True
>>>>> $Excel = $Excel.Workbooks.Add()
>>>>> $Sheet = $Excel.Worksheets.Item(1)
>>>>> $Sheet.Cells.Item(1,1) = "MACHINE NAME"
>>>>> $Sheet.Cells.Item(1,2) = "OPERATING SYSTEM"
>>>>> $Sheet.Cells.Item(1,3) = "STATUS"
>>>>> $intRow = 2
>>>>> $WorkBook = $Sheet.UsedRange
>>>>> $WorkBook.Interior.ColorIndex = 5
>>>>> $WorkBook.Font.ColorIndex = 19
>>>>> $WorkBook.Font.Bold = $True
>>>>> $Machine = Get-Content "C:\Data\ESCG\MachineList3.Txt"
>>>>> $System = Get-WMIObject Win32_OperatingSystem -ComputerName
>>>>> $Machine
>>>>> ForEach($objItem in $System)
>>>>> {
>>>>> $Sheet.Cells.Item($intRow, 1) = $objItem.CSName
>>>>> $Sheet.Cells.Item($intRow, 2) = $objItem.Caption
>>>>> $path = Test-Path "\\$Machine\c$\Program Files\Symantec
>>>>> Antivirus\VPC32.exe"
>>>>> If ($path -eq "True"){
>>>>> $Sheet.Cells.Item($intRow, 3).Interior.ColorIndex = 4
>>>>> $Sheet.Cells.Item($intRow, 3) = "Good"
>>>>> }
>>>>> Elseif ($path -eq "False"){
>>>>> $Sheet.Cells.Item($intRow, 3).Interior.ColorIndex = 3
>>>>> $Sheet.Cells.Item($intRow, 3) = "Needs Attention!"
>>>>> }
>>>>> $intRow = $intRow + 1
>>>>> }
>>>>> $WorkBook.EntireColumn.AutoFit()


