2016-11-05 2 views
1

Ich möchte dieses Skript freigeben Ransom-Ware zu blockieren und später mit allen teilen. Der einzige Punkt, an dem ich bei diesem Hinzufügen von mehreren Laufwerken feststecke und Fehler oder Erfolg beim Erstellen von Dateien erhalte.Catch Erfolg und Fehler

Was dies tun, ist

  1. installieren FSRM arbeiten.
  2. Erstellen Sie Datei Bildschirm funktioniert etwas falsch mit Laufwerken kann nicht mehr als 1 auswählen.
  3. Es sollte fangen, wenn Dateien erstellt werden, so können wir sagen, es ist fehlgeschlagen.
  4. Catch Zugriff verweigert und sagen, es funktioniert. von Nutzen Sie

Hoffnung jemand in der Lage

#Check If FSRM is Are Already Installed 
$check = Get-WindowsFeature | Where-Object {$_.Name -eq "FS-Resource-Manager"} 
if ($check.Installed -ne "True") { 
    Install-WindowsFeature -Name FS-Resource-Manager -IncludeManagementTools 
} else { 
    Write-Host "Cool FSRM is already installed" -F Green 
} 

#define drive letters here 
$drive = @("D:\", "E:\", "C:\users") 

#Create notification is required 

#$Notification = New-FsrmAction -Type Email -MailTo "[Admin Email];[File Owner]" -Subject "Warning: attempted to create a Ransomeware file text file" -Body "You attempted to create a Ransomeware. This is not allowed." -RunLimitInterval 120 

New-FsrmFileGroup -Name "Anti-Ransomware File Groups" -IncludePattern @((Invoke-WebRequest -Uri "https://fsrm.experiant.ca/api/v1/combined" -UseBasicParsing).Content | 
    ConvertFrom-Json | % {$_.filters}) 

New-FsrmFileScreen -Path "$drive" -IncludeGroup "Anti-Ransomware File Groups" -Active # -Notification $Notification 

#test if its working 
try { 
    New-Item "$drive\$(get-random).xtbl" -Type File -ErrorAction Stop 
    Write-Verbose "[RANSOMEWARE CONFIGURATION FAILED] Created $FullName" 
} catch { 
    $ErrorMessage = $_.Exception.Message 
    Write-Warning "[ERROR] access Denied" 
    Write-Host "Congrats you have successfully configured Ransomeware block Sit back and relax" 
} 
+0

Would Shay Levi Antwort helfen? http://stackoverflow.com/questions/8693675/check-if-a-command-has-successfully-ran – Kage

+0

t denke nicht, so dass wir nicht wmi verwenden müssen – DisplayName

+0

Bezieht sich mehr auf die $? Da es sich um eine automatische Variable handelt, die den Erfolg Ihres vorherigen Befehls betrifft, haben Sie die Antwort von Shay Levi nicht überprüft. – Kage

Antwort

0

Erfolg in diesem Thema

$disks = GET-WMIOBJECT win32_logicaldisk -filter "DriveType='3'" | Where {$_.deviceid -ne "C:"} 
      ForEach($disk in $disks) { 
             $DRIVE = $DISK.DeviceID 

            New-FsrmFileScreen -Path "$Drive\" –IncludeGroup "Anti-Ransomware File Groups" -Active # -Notification $Notification 

            } 

#Test if its sucess 

            foreach($Disk in $disks) { 
             $DRIVE = $DISK.DeviceID 

Try 
    { 
     #$newpath=Join-Path -Path $Drive -ChildPath "$(Get-Random).xtbl" 
     $File = New-Item "$drive\$(Get-Random).xtbl"-type file -ErrorAction Stop -ErrorVariable 'ErrorMessage' 
     Write-host "[RANSOMEWARE CONFIGURATION FAILED] Created $($File.FullName)" -ForegroundColor red 
    } 

    Catch 
    { 
     Write-Warning "[ERROR] access Denied" 
     Write-Output "File not created: $($File.FullName)" 
     Write-Host "Congrats you have successfully configured Ransomeware block Sit back and relax" -f green 
    } 
    } 

    ##### create File screen and block all the shared items 


    $paths=Get-WmiObject Win32_Share | Select Name,Path,Type | Where-Object { $_.Type -eq 0 } | Select -ExpandProperty Path 

    foreach($path in $paths){ 
New-FsrmFileScreen -Path "$path" –IncludeGroup "Anti-Ransomware File Groups" -Active # -Notification $Notification 

}