Help with Script

This topic contains 5 replies, has 3 voices, and was last updated by  Alex Aymonier 3 weeks, 4 days ago.

  • Author
    Posts
  • #80009

    Rocky Ramirez
    Participant

    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.
    Rocky
    foreach ($pc in (get-adcomputer -searchbase "OU=Laptops,OU=Computers,OU=_____, OU=NA, OU=Regions, DC=___, DC=____, DC=___" -filter *|where{$_.enabled}).Name) {
    $pc
    invoke-command -ComputerName $pc -scriptblock {Start-Process -FilePath "\\_____\temp$\CC\CCleaner64.exe" -ArgumentList "/CLEANER /AUTO"}
    }

  • #80689

    Alex Aymonier
    Participant

    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.

    • #80756

      Rocky Ramirez
      Participant

      All computers are failing with script.

    • #80768

      Alex Aymonier
      Participant

      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) {
          $pc
          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.

  • #80744

    Naw Awn
    Participant

    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
    }
    
  • #80746

    Naw Awn
    Participant

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

You must be logged in to reply to this topic.