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

Ask your 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.
This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ITEngineer
Posts: 216
Last visit: Thu Mar 23, 2023 5:45 pm
Has voted: 4 times

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

Post by ITEngineer »

jvierra wrote: Thu Jan 10, 2019 9: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 */
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

Just run this:

Get-RemoteProgram -Computername WKS021
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

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

This topic is 5 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked