PowerShell script to Get-RemotePrograms and export to .CSV for multiple AD computer object not working for bulk?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
ITEngineer
Posts: 138
Joined: Wed Oct 12, 2011 10:52 am

Re: PowerShell script to Get-RemotePrograms and export to .CSV for multiple AD computer object not working for bulk?

Post by ITEngineer » Thu Jan 10, 2019 10:09 pm

jvierra wrote:
Thu Jan 10, 2019 10:04 pm
This would be easier to work with and debug.

Code: Select all

$OUList = @(
    'OU=Workstations,OU=Testing,DC=Domain,DC=com',
    'OU=Desktops,DC=Domain,DC=com',
    'OU=Laptops,DC=Domain,DC=com'
)

$computers = ForEach-Object{
    Get-ADComputer -Properties Name -Filter { Enabled -eq $True -and OperatingSystem -like "*Windows*" } -SearchBase $_ |
        Where-Object { Test-Connection $_.Name -Count 1 -Quiet }
}

$computers |
    ForEach-Object {
        Write-Host "Checking $($_.Name) ..."
        Get-RemoteProgram -ComputerName $_.Name -IncludeProgram '*Office*'
    } |
    Sort-Object ProgramName |
    Export-Csv -Path C:\Logs\Office.txt -NoTypeInformation
It cannot retrieve the value of $OUList?

Hence the error:
Get-ADComputer : Cannot validate argument on parameter 'SearchBase'. The argument is null. Provide a valid value for the argument, and then try running the command again.At line:249 char:118
+ ... d -eq $True -and OperatingSystem -like "*Windows*" } -SearchBase $_ |
+ ~~
+ CategoryInfo : InvalidData: (:) [Get-ADComputer], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADComputer
/* IT Engineer */

User avatar
jvierra
Posts: 13292
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell script to Get-RemotePrograms and export to .CSV for multiple AD computer object not working for bulk?

Post by jvierra » Thu Jan 10, 2019 10:14 pm

Just run this:

Get-RemoteProgram -Computername WKS021

User avatar
jvierra
Posts: 13292
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: PowerShell script to Get-RemotePrograms and export to .CSV for multiple AD computer object not working for bulk?

Post by jvierra » Thu Jan 10, 2019 10:41 pm

Sorry typo -

Code: Select all

$OUList = @(
    'OU=Workstations,OU=Testing,DC=Domain,DC=com',
    'OU=Desktops,DC=Domain,DC=com',
    'OU=Laptops,DC=Domain,DC=com'
)

$computers = $OUList |
    ForEach-Object{
        Get-ADComputer -Properties Name -Filter { Enabled -eq $True -and OperatingSystem -like "*Windows*" } -SearchBase $_ |
        Where-Object { Test-Connection $_.Name -Count 1 -Quiet }
    }

$computers |
    ForEach-Object {
        Write-Host "Checking $($_.Name) ..."
        Get-RemoteProgram -ComputerName $_.Name -IncludeProgram '*Office*'
    } |
    Sort-Object ProgramName |
    Export-Csv -Path C:\Logs\Office.txt -NoTypeInformation


Locked