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. #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

  3. #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

  4. #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

  5. #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

  6. #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

  7. #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

  8. #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

  9. #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

  10. #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
I am setting up a small network containing three computers all running vista. I will refer to them as Comp 1, Comp 2, Comp 3. Comp 2 and 3 are...
Vista networking & sharing
Running multiple versions of Firefox
I have both Minefield 64-bit and regular Firefox installed but whenever I run Minefield, Firefox always appears. I suspect its something to do with...
Software
Running multiple instances of an application
I trade stocks with multiple brokers and therefore use multiple trading applications. Two of my brokers use the same trading software, InstaQuote....
Vista General
adding vista comps to an existing network
can vista home basic work with windows server 2003?
Vista networking & sharing
Trouble getting Vista to see the other comps.
I have a home network with two desktops ( One running XP Home, and one running 2000 Pro) and a new laptop with Vista Home Premium. I set up the...
Vista networking & sharing
multiple sidebar.exe running
we have been trying out the sidebar feature and using custom gadgets downloaded from the marketplace (multimeter,dopplar, and such) and have...
Vista General
running multiple processes in background
I have a few scripts that I want to run at the same time. If there a method to execute scripts in the background, ie, script1.ps1 & script2.ps1...
PowerShell