2017-05-11 17 views
0

我的任務是創建一個報告,我需要找到只有Office 365 ProPlus而不是OneDrive的機器。我們有一個混合的環境,出於商業目的,一些機器都有,而其他機器只有O365。我需要所有具有O365的機器清單(清除O365 \ OneDrive組合機器)。僅當其他軟件不存在時才使用特定軟件查找機器

這是我目前:

$OutPath = "c:\Machines_with_O365.csv" 
$Software = "Microsoft Office 365 ProPlus*" 

$Computers = Get-ADComputer -Filter * 
foreach ($Computer in $Computers) { 
    $Ping = Test-Connection -ComputerName $Computer.Name -Quiet -Count 1 
    if ($Ping -eq $true) { 
     try { 
      $MachineName = $Computer.Name 
      Get-WmiObject -Class Win32_Product -ComputerName $computer.Name -ErrorAction Stop | 
       ? {$_.Name -like $Software} | 
       Select-Object @{N="ComputerName";E={$Computer.Name}}, Vendor, Name | 
       Export-Csv $OutPath -Append 
     } catch { 
      Write-Host "Unable to Obtain WMI Object of $MachineName" 
     } 
    } 
} 
if ($Ping -eq $false) { 
    Write-Host "The $MachineName is not pingable" 
} 

我需要什麼添加\變化讓我到終點?

回答

0

您需要檢查已安裝軟件的列表是否包含一個程序,但不包含其他程序。嘗試是這樣的:

$MachineName = $Computer.Name 
$softwarList = Get-WmiObject -Class Win32_Product -Computer $MachineName -ErrorAction Stop 
if ($softwareList -contains $Software -and $softwareList -notcontains $OneDrive) { 
    $softwareList | 
     Select-Object @{n='ComputerName';e={$MachineName}}, Vendor, Name | 
     Export-Csv $OutPath -Append 

即使被警告,該Win32_Product類是considered harmful,因爲查詢的那類可能引發一個包重新配置。

相關問題