Help with Script

Hey Everyone,
I made some progress but I am still getting “Access is denied” error codes coming back from computers. Anyone have suggestions? The underlines have script in them I have just removed for security purposes.
foreach ($pc in (get-adcomputer -searchbase “OU=Laptops,OU=Computers,OU=, OU=NA, OU=Regions, DC=, DC=, DC=" -filter *|where{$.enabled}).Name) {
invoke-command -ComputerName $pc -scriptblock {Start-Process -FilePath "\
___\temp$\CC\CCleaner64.exe” -ArgumentList “/CLEANER /AUTO”}

If you run this for just one computer does it work? Is it all computers failing? You should also look at the double hop problem as the path you are using in invoke-command looks to be remote to the system you are remoting to.

Hey Rocky

Inovke-Command is very powerful if you set up your environment with WinRM PSRemoting and set-Executionpolicy set to ‘RemoteSigned’.
It can also fan out your command across the whole network in parallel. But if you haven’t got it working you can always use Invoke-WmiMethod as below. Be aware that this command doesn’t like UNC path that begins with \. It uses the local path on the remote machine. In your case, CCleaner would have already been installed. So, just use the local path (absolute path).

$Computers = Get-DdComputer -SearchBase "OU=Laptops,OU=Computers,OU=_____, OU=NA, OU=Regions, DC=___, DC=____, DC=___" -filter *|where{$_.enabled}).Name)
Foreach($PC in $Computers){
    Write-Output $PC
    Invoke-WmiMethod Win32_Process -Name Create -ArgumentList 'C:\temp\CC\CCleaner64.exe "/CLEANER /AUTO"' -ComputerName $PC

$Computers = (Get-AdComputer -SearchBase “OU=Laptops,OU=Computers,OU=, OU=NA, OU=Regions, DC=, DC=, DC=” -Filter * | where{$_.enabled}).Name

All computers are failing with script.

Ok if all are failing try something simple that is non destructive 1st like “Get-Service -Name BITS”

foreach ($pc in (get-adcomputer -searchbase "OU=Laptops,OU=Computers,OU=_____, OU=NA, OU=Regions, DC=___, DC=____, DC=___" -filter *|where{$_.enabled}).Name) {
    invoke-command -ComputerName $pc -scriptblock {Get-Service -Name BITS}

If this still fails concentrate on one computer 1st and try a enter-pssession and see if remoting works and get that working.