Q:

Powershell scan txt file then run command

I am trying to scan a folder for when a text file comes it grabs the two lines of text and runs the command to shutdown the azure server in the text file. I would also like it to delete the text file after it reads it. I am not sure if I am doing this correctly and I have pieced together some scripts I found. Currently it will read that there has been a file added but does not do anything with the information and does not run the shutdown. Any help would be much appreciated. 
$folder = 'c:\ftptest' # Enter the root path you want to monitor. 
$filter = '*.*'  # You can enter a wildcard filter here. 
$fsw = New-Object IO.FileSystemWatcher $folder, $filter -Property @{IncludeSubdirectories = $false;NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'} 

# Run Event 

Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action { 
$name = $Event.SourceEventArgs.Name 
$changeType = $Event.SourceEventArgs.ChangeType 
$timeStamp = $Event.TimeGenerated
$cloudSvcName,$vmname = Get-Content $name | Out-String
Write-Host "The file '$name' was $changeType at $timeStamp" -fore green 
Out-File -FilePath c:\scripts\logs\outlog.txt -Append -InputObject "The file '$name' was $changeType at $timeStamp '$cloudSvcName' '$vmname' "
Stop-AzureVM -servicename $cloudSvcName -name $vmname -force} 

A:

Here is what I ended up doing. It watches a folder runs the powershell with the first two lines of text as the azure cloud service name and vmname and then logs it. I am using freeSSHd on the windows server to accept sftp being sent to it from a linux box. 
# watch a file changes in the current directory, 
# execute all tests when a file is changed or renamed

$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = 'C:\ftpsites\centos'
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $false
$watcher.NotifyFilter = [System.IO.NotifyFilters]::LastWrite -bor [System.IO.NotifyFilters]::FileName

while($TRUE){
    $result = $watcher.WaitForChanged([System.IO.WatcherChangeTypes]::Changed -bor [System.IO.WatcherChangeTypes]::Renamed -bOr [System.IO.WatcherChangeTypes]::Created, 1000);
    if($result.TimedOut){
        continue;
    }
    write-host "Change in " + $result.Name
Start-Sleep -s 1
    $name = $result.Name
    $cloudSvcName,$vmname = Get-Content 'C:\ftpsites\centos\*.txt'
    $date = Get-Date -Format g
    stop-azurevm -servicename $cloudSvcName -name $vmname -force
    del C:\ftpsites\centos\*.txt
    Out-File -FilePath c:\scripts\logs\filewatcher.txt -Append -InputObject "$date $name"
}

