I need to export the .CSV for all computers with Microsoft Office installed, hence I've stumbled upon this script: https://gallery.technet.microsoft.com/G ... b4#content
When I run the script using one line of code at the end of the file, it can give me the result successfully:
However, when I modify/enhance it using the below codes I pasted at the end of the Get-RemoteProgram.ps1 script, it throws out some errors:Get-RemoteProgram -ComputerName 'MyLaptop01-NEW' -IncludeProgram ('*Office*') | Sort-Object ProgramName | Export-Csv -Path C:\Logs\Office.txt -NoTypeInformation
Code: Select all
$OUList = @(
"OU=Workstations,OU=Testing,DC=Domain,DC=com"
"OU=Desktops,DC=Domain,DC=com"
"OU=Laptops,DC=Domain,DC=com"
)
$OUList | ForEach-Object {
$OU = $_
$Computers = Get-ADComputer -Properties Name -Filter { Enabled -eq $True -and OperatingSystem -like "*Windows*" } -SearchBase $OU |
Where-Object {Test-Connection $_.Name -Count 1 -Quiet} |
Select-Object -ExpandProperty Name |
Sort-Object
ForEach ($Computer in $Computers) {
Write-Host "Checking $Computer ..."
Get-RemoteProgram -ComputerName $Computer -IncludeProgram ('*Office*') | Sort-Object ProgramName | Export-Csv -Path C:\Logs\Office.txt -NoTypeInformation
}
}
Checking WKS042... Get-RemoteProgram : Exception calling "OpenRemoteBaseKey" with "2" argument(s): "The network path was not found.
"
At line:258 char:9
+ Get-RemoteProgram -ComputerName $Computer -IncludeProgram ('* ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RemoteProgram
Checking WKS021...
Get-RemoteProgram : Exception calling "OpenRemoteBaseKey" with "2" argument(s): "Attempted to perform an unauthorized operation."
At line:258 char:9
+ Get-RemoteProgram -ComputerName $Computer -IncludeProgram ('* ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Get-RemoteProgram
Any help to fix the code above is appreciated.
Thanks in advance.