Windows Vista Forums

Running in multiple comps

  1. #1


    Rajeev Guest

    Running in multiple comps

    Hi,

    I'm trying to find a way to run the following script in multiple
    remote computers.

    Move-Item c:\test\*.log d:\test
    $Size = Get-Item d:\test
    if ($size.length/1MB -ge 1024)
    {
    $a = Get-ChildItem "d:\test"
    foreach($x in $a)
    {
    $y = ((Get-Date) - $x.LastWriteTime).Days
    if ($y -ge 10 -and $x.PsISContainer -ne $True)
    {$x.Delete()}
    }
    }

    Can anyone help please. Thanks

      My System SpecsSystem Spec

  2.   


  3. #2


    Joel (Jaykul) Bennett Guest

    Re: Running in multiple comps

    The best way would be using invoke-expression with the V2 CTP
    bits ....

    $cmd= @:
    Move-Item c:\test\*.log d:\test
    $Size = Get-Item d:\test
    if ($size.length/1MB -ge 1024)
    {
    $a = Get-ChildItem "d:\test"
    foreach($x in $a)
    {
    $y = ((Get-Date) - $x.LastWriteTime).Days
    if ($y -ge 10 -and $x.PsISContainer -ne $True)
    {$x.Delete()}
    }

    }
    "@

    invoke-expression -computername (get-content machines.txt) -command
    $cmd

      My System SpecsSystem Spec

  4. #3


    Brandon Shell [MVP] Guest

    Re: Running in multiple comps

    Use UNC paths for Computers

    Something like this
    foreach($comp in $computers)
    {
    Move-Item \\$comp\c$\test\*.log \\$comp\d$\test
    $Size = Get-Item \\$comp\d$\test
    if ($size.length/1MB -ge 1024)
    {
    $a = Get-ChildItem \\$comp\d$\test
    foreach($x in $a)
    {
    $y = ((Get-Date) - $x.LastWriteTime).Days
    if ($y -ge 10 -and $x.PsISContainer -ne $True)
    {$x.Delete()}
    }
    }
    }
    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    R> Hi,
    R>
    R> I'm trying to find a way to run the following script in multiple
    R> remote computers.
    R>
    R> Move-Item c:\test\*.log d:\test
    R> $Size = Get-Item d:\test
    R> if ($size.length/1MB -ge 1024)
    R> {
    R> $a = Get-ChildItem "d:\test"
    R> foreach($x in $a)
    R> {
    R> $y = ((Get-Date) - $x.LastWriteTime).Days
    R> if ($y -ge 10 -and $x.PsISContainer -ne $True)
    R> {$x.Delete()}
    R> }
    R> }
    R> Can anyone help please. Thanks
    R>



      My System SpecsSystem Spec

  5. #4


    Marco Shaw [MVP] Guest

    Re: Running in multiple comps

    Rajeev wrote:

    > Hi,
    >
    > I'm trying to find a way to run the following script in multiple
    > remote computers.
    >
    > Move-Item c:\test\*.log d:\test
    > $Size = Get-Item d:\test
    > if ($size.length/1MB -ge 1024)
    > {
    > $a = Get-ChildItem "d:\test"
    > foreach($x in $a)
    > {
    > $y = ((Get-Date) - $x.LastWriteTime).Days
    > if ($y -ge 10 -and $x.PsISContainer -ne $True)
    > {$x.Delete()}
    > }
    > }
    >
    > Can anyone help please. Thanks
    OK, you're looking for remoting functionality so you can run a
    PowerShell command from where you're sitting, and have it run on remote
    machines and return the info back to you?

    There is this functionality in the v2 CTP (next version of PowerShell
    currently under development), but this is not meant for a production
    environment.

    In version 1, there isn't a real efficient/easy way to do this.

    Do you have winrm installed in your environment?

    Marco

    --
    Microsoft MVP - Windows PowerShell
    http://www.microsoft.com/mvp

    PowerGadgets MVP
    http://www.powergadgets.com/mvp

    Blog:
    http://marcoshaw.blogspot.com

      My System SpecsSystem Spec

  6. #5


    Shay Levi Guest

    Re: Running in multiple comps



    $computers = "comp1","comp2","comp3"

    $computers | foreach {
    dir \\$_\c$\test\*.log | where {!$_.PsISContainer -and ($_.length -ge
    1mb) -and ((Get-Date) - $_.LastWriteTime).Days -ge 10 )} | remove-item -force
    -whatIf
    }



    -----
    Shay Levi
    $cript Fanatic
    http://scriptolog.blogspot.com

    > Hi,
    >
    > I'm trying to find a way to run the following script in multiple
    > remote computers.
    >
    > Move-Item c:\test\*.log d:\test
    > $Size = Get-Item d:\test
    > if ($size.length/1MB -ge 1024)
    > {
    > $a = Get-ChildItem "d:\test"
    > foreach($x in $a)
    > {
    > $y = ((Get-Date) - $x.LastWriteTime).Days
    > if ($y -ge 10 -and $x.PsISContainer -ne $True)
    > {$x.Delete()}
    > }
    > }
    > Can anyone help please. Thanks
    >


      My System SpecsSystem Spec

  7. #6


    Marco Shaw [MVP] Guest

    Re: Running in multiple comps

    Brandon Shell [MVP] wrote:

    > Use UNC paths for Computers
    Minor warning to the user: this could be slow.

      My System SpecsSystem Spec

  8. #7


    Joel (Jaykul) Bennett Guest

    Re: Running in multiple comps

    or you could use psexec to copy over the script and ...
    But for this particular script, I gotta agree with Brandon

      My System SpecsSystem Spec

  9. #8


    Rajeev Guest

    Re: Running in multiple comps

    Thanks Brandon. I had a thought about that. Still wanted to check if i
    could take the names from a file. This should be fine.

    One more question: how will i run this script again after say 10hrs

    Thanks


      My System SpecsSystem Spec

  10. #9


    Brandon Shell [MVP] Guest

    Re: Running in multiple comps

    schedule tasked.

    Brandon Shell
    ---------------
    Blog: http://www.bsonposh.com/
    PSH Scripts Project: www.codeplex.com/psobject

    R> Thanks Brandon. I had a thought about that. Still wanted to check if
    R> i could take the names from a file. This should be fine.
    R>
    R> One more question: how will i run this script again after say 10hrs
    R>
    R> Thanks
    R>



      My System SpecsSystem Spec

  11. #10


    Rajeev Guest

    Re: Running in multiple comps

    Thanks Shay Levi,

    How would i run the same process after 10 hrs... This should
    automatically run every 10 hrs.

    Thanks

      My System SpecsSystem Spec

Page 1 of 2 12 LastLast

Running in multiple comps
Similar Threads
Thread Forum
Mapping 3 Vista comps, can not see each other Vista networking & sharing
Running multiple versions of Firefox Software
adding vista comps to an existing network Vista networking & sharing
Trouble getting Vista to see the other comps. Vista networking & sharing
multiple sidebar.exe running Vista General