Page 2 of 2

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

Posted: Thu Jan 10, 2019 10:09 pm
by ITEngineer
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

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

Posted: Thu Jan 10, 2019 10:14 pm
by jvierra
Just run this:

Get-RemoteProgram -Computername WKS021

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

Posted: Thu Jan 10, 2019 10:41 pm
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