Help with Script

Welcome Forums General PowerShell Q&A Help with Script

This topic contains 5 replies, has 3 voices, and was last updated by

 
Participant
1 year, 2 months ago.

  • Author
    Posts
  • #80009

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 87
    Helping Hand
    Rank: Member

    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

      Participant
      Points: 0
      Rank: Member

      All computers are failing with script.

    • #80768

      Participant
      Points: 87
      Helping Hand
      Rank: Member

      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

    Participant
    Points: 7
    Rank: Member

    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

    Participant
    Points: 7
    Rank: Member

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

The topic ‘Help with Script’ is closed to new replies.