Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8506559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:37:26+00:00 2026-06-11T02:37:26+00:00

Hi I have installed the PowerShellPack and I am using the FileSystem watcher module,but

  • 0

Hi I have installed the PowerShellPack and I am using the FileSystem watcher module,but the problem when I safe the file as a script and execute it.

The problem is that if you execute the script it runs and the monitors the folder for changes but once the script stops (gets to the end of execution) the folder is no longer monitored.
I have tried to place everything in a do while loop but that does not seem to work.

PowerShellPack Install

Import-Module -Name FileSystem


$TempCopyFolder = "c:\test"
$PatchStorage = "c:\testpatch"


Start-FileSystemWatcher -File $TempCopyFolder  -Do {   
    $SearchPath = $File
    $PatchesPath = $PatchStorage
    $NewFolderFullPath = "$($eventArgs.FullPath)"
    $NewFolderName = "$($eventArgs.Name)"
    $PathToCheck = "$PatchesPath\$NewFolderName"

    #Check if it is a filde or folder 
    switch ($ObjectType) 
           {{((Test-Path $NewFolderFullPath -PathType Container) -eq $true)}{$ObjectType = 1;break}
           {((Test-Path  $NewFolderFullPath -PathType Leaf) -eq $true)}{$ObjectType = 2;break}} 

    # Its a folder so lets check if we have a folder in the $PatchesPath already
    IF($ObjectType -eq 1){
       IF(!(Test-Path -LiteralPath $PathToCheck -EA 0))
           {
            sleep -Seconds 3

            #Make a new directory where we store the patches
              New-item -Path $PatchesPath -Name $NewFolderName -ItemType directory

            #Make a folde in the folder for TC1
            $TcFolder=$NewFolderName + '_1'
            $NewPatchesPath = "$PatchesPath\$NewFolderName"

            New-item -path $NewPatchesPath -Name $TcFolder -ItemType directory

            $CopySrc = $NewFolderFullPath
            $CopyDes = "$NewPatchesPath\$TcFolder"

           }

       # There is a folder there so lets get the next number
       Else{

            $HighNumber = Get-ChildItem -Path $PathToCheck | select -Last 1

            #Core_SpanishLoginAttemptsConfiguration_Patch_03                                       

            $NewNumber = [int](Select-String -InputObject $HighNumber.Name -Pattern "(\d\d|\d)" | % { $_.Matches } | % { $_.Value } )+1
            $TcFolder= $NewFolderName + '_' + $NewNumber

            $NewPatchesPath = "$PatchesPath\$NewFolderName"

            $CopySrc = $NewFolderFullPath
            $CopyDes = "$NewPatchesPath\$TcFolder"
           }

         #Lets copy the files to their new home now that we know where every thing goes 

         $robocopy = "robocopy.exe"
         $arguments = '''' + $CopySrc + '''' +' '+ ''''+ $CopyDes + '''' + '/E'

         Invoke-Expression  -Command "$robocopy $arguments"

         Do {sleep -Seconds 1;$p = Get-Process "robo*" -ErrorAction SilentlyContinue}
             While($p -ne $null)

        #Now lets check every thing copyed 

        $RefObj = Get-ChildItem -LiteralPath $NewFolderFullPath -Recurse
        $DifObj = Get-ChildItem -LiteralPath $CopyDes -Recurse

        IF(Compare-Object -ReferenceObject $RefObj -DifferenceObject $DifObj)
           {write-host "Fail"}
        Else{# Now lets delete the source

             Remove-Item -LiteralPath $CopySrc -Force -Recurse
             }     
}} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:37:28+00:00Added an answer on June 11, 2026 at 2:37 am

    This is something you probably need: Monitoring file creation using WMI and PowerEvents module

    PowerEvents Module isn’t mandatory if you know how to create Permanent Events in WMI. For more information on that, check my eBook on WQL via PowerShell: http://www.ravichaganti.com/blog/?page_id=2134

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed C++SDK that have Qt but when I try compiling a code
I have installed my dependencies using bundle package Then transferred them to the offline
I have installed pyglet onto Mac OS X 10.7.4 using MacPorts. pyglet only works
We have installed OpenDataKit (ODK) Aggregate and we are using a MySQL Database. I
I have installed new site in Joomla 1.7 and its working fine, but when
I have installed wxWidgets 2.9.3 on Ubuntu 10.10 using ../configure --with-gtk I am using
I have installed rvm (mutiuser option) and ruby using rvm install on my test
I have installed mySQL using sudo apt-get install mySQL-server then i have installed libmysqlclient15-dev
I have installed 1.1.9 Yii framework.Then I made copy paste user module in my
I have installed tomcat 6 and 7 to the port 8080. I am using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.