{"id":385089,"date":"2024-11-20T14:50:53","date_gmt":"2024-11-20T14:50:53","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=385089"},"modified":"2024-11-20T14:50:53","modified_gmt":"2024-11-20T14:50:53","slug":"existenz-von-dateien-ueberpruefen","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/de\/script-hub\/existenz-von-dateien-ueberpruefen\/","title":{"rendered":"Wie man die Existenz von Dateien oder Ordnern unter Windows mit einem PowerShell-Skript \u00fcberpr\u00fcft"},"content":{"rendered":"<p>In der modernen IT-Welt kann die Verwaltung und Pflege von Dateisystemen auf zahlreichen Servern und Workstations eine Herausforderung darstellen. IT-Experten und <a href=\"https:\/\/www.ninjaone.com\/de\/was-ist-ein-msp\/\" target=\"_blank\" rel=\"noopener\">Managed Service Provider (MSPs)<\/a> m\u00fcssen h\u00e4ufig <strong>bestimmte Dateien und Verzeichnisse \u00fcberwachen<\/strong>, um die Compliance, Sicherheit und betriebliche Effizienz zu gew\u00e4hrleisten.<\/p>\n<p>Eine zuverl\u00e4ssige Methode zur Bew\u00e4ltigung dieser Aufgabe ist die Verwendung von <a href=\"https:\/\/www.ninjaone.com\/de\/it-hub\/endpoint-management\/was-ist-powershell\/\" target=\"_blank\" rel=\"noopener\">PowerShell-Skripten<\/a>, die Automatisierung und detaillierte Kontrolle \u00fcber Windows-Umgebungen bietet. Das mitgelieferte PowerShell-Skript wurde entwickelt, um Benutzer:innen zu benachrichtigen, wenn eine bestimmte Datei oder ein bestimmter Ordner innerhalb eines bestimmten Verzeichnisses oder Unterverzeichnisses gefunden wird, was es zu einem wertvollen Tool f\u00fcr IT-Experten macht.<\/p>\n<h2>Kontext<\/h2>\n<p>Die \u00dcberwachung des Vorhandenseins und des Speicherorts von Dateien ist aus mehreren Gr\u00fcnden wichtig. Dieser Prozess hilft bei der Aufrechterhaltung der Sicherheit, indem er sicherstellt, dass keine unautorisierten Dateien vorhanden sind, unterst\u00fctzt die Compliance, indem es \u00fcberpr\u00fcft, ob die erforderlichen Dateien zur Verf\u00fcgung stehen, und hilft bei der betrieblichen Effizienz durch die Automatisierung von Routinepr\u00fcfungen. Dieses Skript ist besonders n\u00fctzlich f\u00fcr IT-Experten, die gro\u00dfe Netzwerke oder mehrere Kundenumgebungen verwalten m\u00fcssen. Durch die Automatisierung des Such- und Warnprozesses wird Zeit gespart und das Risiko menschlichen Versagens verringert.<\/p>\n<h2>Das Skript zur \u00dcberpr\u00fcfung der Existenz von Dateien oder Ordnern unter Windows<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Alert if a specified file or folder is found in a directory or subdirectory you specify.\r\n.DESCRIPTION\r\n    Alert if a specified file or folder is found in a directory or subdirectory you specify.\r\n\r\n.EXAMPLE\r\n    -SearchPath \"C:\" -FileOrFolder \"autounattend\"\r\n\r\n    WARNING: Backslash missing from the search path. Changing it to C:\\.\r\n    [Alert] File Found.\r\n    C:\\Users\\Administrator\\Desktop\\ExampleFolder\\Test Folder 1\\autounattend.xml\r\n    C:\\Users\\Administrator\\Desktop\\ExampleFolder\\Test Folder 2\\autounattend.xml\r\n    C:\\Users\\Administrator\\Desktop\\ExampleFolder\\TestFolder1\\Test Folder 1\\autounattend.xml\r\n    C:\\Users\\Administrator\\Desktop\\ExampleFolder\\TestFolder1\\Test Folder 2\\autounattend.xml\r\n    C:\\Users\\Administrator\\Desktop\\ExampleFolder\\TestFolder2\\Test Folder 1\\TestFolder1\\autounattend.xml\r\n    Attempting to set Custom Field 'multiline'.\r\n    Successfully set Custom Field 'multiline'!\r\n\r\nPARAMETER: -SeachPath \"C:\\ReplaceMeWithAvalidPath\"\r\n    Enter the starting directories for the search, separated by commas. This will include all subdirectories as well.\r\n\r\nPARAMETER: -FileOrFolder \"ReplaceMeWithNameToSearchFor\"\r\n    Specify the full or partial name of a file or folder to find. E.g., 'config' or '.exe'.\r\n\r\nPARAMETER: -SearchType \"Files and Folders\"\r\n    Limit the search to either files, folders, or both.\r\n\r\nPARAMETER: -Timeout \"30\"\r\n    Maximum search time in minutes, halts search if exceeded.\r\n\r\nPARAMETER: -CustomField \"ReplaceMeWithNameOfMultilineCustomField\"\r\n    Optional multiline field to record search results. Leave blank if unused.\r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes: Initial Release\r\nBy using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [String]$SearchPath = \"C:\\Windows,C:\\Program Files\",\r\n    [Parameter()]\r\n    [String]$FileOrFolder,\r\n    [Parameter()]\r\n    [String]$SearchType = \"Files and Folders\",\r\n    [Parameter()]\r\n    [Int]$Timeout = 30,\r\n    [Parameter()]\r\n    [String]$CustomField\r\n)\r\n\r\nbegin {\r\n    # Set parameters using dynamic script variables.\r\n    if ($env:searchPath -and $env:searchPath -notlike \"null\") { $SearchPath = $env:searchPath }\r\n    if ($env:fileNameOrFolderNameToSearchFor -and $env:fileNameOrFolderNameToSearchFor -notlike \"null\") { $FileOrFolder = $env:fileNameOrFolderNameToSearchFor }\r\n    if ($env:searchType -and $env:searchType -notlike \"null\") { $SearchType = $env:searchType }\r\n    if ($env:timeoutInMinutes -and $env:timeoutInMinutes -notlike \"null\") { $Timeout = $env:timeoutInMinutes }\r\n    if ($env:customFieldName -and $env:customFieldName -notlike \"null\") { $CustomField = $env:customFieldName }\r\n\r\n    # Error out if no search path was given.\r\n    if (-not $SearchPath) {\r\n        Write-Host \"[Error] No search path given!\"\r\n        exit 1\r\n    }\r\n\r\n    # If given a comma-separated list, split the paths.\r\n    $PathsToSearch = New-Object System.Collections.Generic.List[String]\r\n    if ($SearchPath -match \",\") {\r\n        $SearchPath -split \",\" | ForEach-Object { $PathsToSearch.Add($_.Trim()) }\r\n    }\r\n    else {\r\n        $PathsToSearch.Add($SearchPath)\r\n    }\r\n\r\n    # Initialize a generic list for paths to remove or replace.\r\n    $ReplacementPaths = New-Object System.Collections.Generic.List[Object]\r\n    $PathsToRemove = New-Object System.Collections.Generic.List[String]\r\n\r\n    # If given a drive without the backslash add it in.\r\n    $PathsToSearch | ForEach-Object {\r\n        if ($_ -notmatch '^[A-Z]:\\\\$' -and $_ -match '^[A-Z]:$') {\r\n            $NewPath = \"$_\\\"\r\n            $ReplacementPaths.Add(\r\n                [PSCustomObject]@{\r\n                    Index   = $PathsToSearch.IndexOf(\"$_\")\r\n                    NewPath = $NewPath\r\n                }\r\n            )\r\n                \r\n            Write-Warning \"Backslash missing from the search path. Changing it to $NewPath.\"\r\n        }\r\n    }\r\n\r\n    # Apply replacements.\r\n    $ReplacementPaths | ForEach-Object {\r\n        $PathsToSearch[$_.index] = $_.NewPath \r\n    }\r\n\r\n    # Check if the search path is valid.\r\n    $PathsToSearch | ForEach-Object {\r\n        if (-not (Test-Path $_)) {\r\n            Write-Host -Object \"[Error] $_ does not exist!\"\r\n            $PathsToRemove.Add($_)\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n\r\n    # Remove Paths that do not exist.\r\n    $PathsToRemove | ForEach-Object {\r\n        $PathsToSearch.Remove($_) | Out-Null\r\n    }\r\n\r\n    # Error out if no valid paths to search.\r\n    if ($($PathsToSearch).Count -eq 0) {\r\n        Write-Host \"[Error] No valid paths to search!\"\r\n        exit 1\r\n    }\r\n\r\n    # If we're not given a file or folder error out.\r\n    if (-not $FileOrFolder) {\r\n        Write-Host -Object \"[Error] No file or folder given to search for!\"\r\n        exit 1\r\n    }\r\n\r\n    # Timeout must be within a given range in minutes.\r\n    if ($Timeout -lt 1 -or $Timeout -gt 120) {\r\n        Write-Host -Object \"[Error] Timeout is greater than 120 minutes or less than 1 minute.\"\r\n        exit 1\r\n    }\r\n\r\n    # Scope the search to either files only or folders only.\r\n    $ValidSearchTypes = \"Files and Folders\", \"Files Only\", \"Folders Only\"\r\n    if ($ValidSearchTypes -notcontains $SearchType) {\r\n        Write-Host -Object \"[Error] Invalid search type.\"\r\n        exit 1\r\n    }\r\n\r\n    # Test for local administrator rights.\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n\r\n    # Handy function to set a custom field.\r\n    function Set-NinjaProperty {\r\n        [CmdletBinding()]\r\n        Param(\r\n            [Parameter(Mandatory = $True)]\r\n            [String]$Name,\r\n            [Parameter()]\r\n            [String]$Type,\r\n            [Parameter(Mandatory = $True, ValueFromPipeline = $True)]\r\n            $Value,\r\n            [Parameter()]\r\n            [String]$DocumentName\r\n        )\r\n    \r\n        $Characters = $Value | Measure-Object -Character | Select-Object -ExpandProperty Characters\r\n        if ($Characters -ge 10000) {\r\n            throw [System.ArgumentOutOfRangeException]::New(\"Character limit exceeded, value is greater than 10,000 characters.\")\r\n        }\r\n        \r\n        # If we're requested to set the field value for a Ninja document we'll specify it here.\r\n        $DocumentationParams = @{}\r\n        if ($DocumentName) { $DocumentationParams[\"DocumentName\"] = $DocumentName }\r\n        \r\n        # This is a list of valid fields that can be set. If no type is given, it will be assumed that the input doesn't need to be changed.\r\n        $ValidFields = \"Attachment\", \"Checkbox\", \"Date\", \"Date or Date Time\", \"Decimal\", \"Dropdown\", \"Email\", \"Integer\", \"IP Address\", \"MultiLine\", \"MultiSelect\", \"Phone\", \"Secure\", \"Text\", \"Time\", \"URL\", \"WYSIWYG\"\r\n        if ($Type -and $ValidFields -notcontains $Type) { Write-Warning \"$Type is an invalid type! Please check here for valid types. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/16973443979789-Command-Line-Interface-CLI-Supported-Fields-and-Functionality\" }\r\n        \r\n        # The field below requires additional information to be set\r\n        $NeedsOptions = \"Dropdown\"\r\n        if ($DocumentName) {\r\n            if ($NeedsOptions -contains $Type) {\r\n                # We'll redirect the error output to the success stream to make it easier to error out if nothing was found or something else went wrong.\r\n                $NinjaPropertyOptions = Ninja-Property-Docs-Options -AttributeName $Name @DocumentationParams 2&gt;&amp;1\r\n            }\r\n        }\r\n        else {\r\n            if ($NeedsOptions -contains $Type) {\r\n                $NinjaPropertyOptions = Ninja-Property-Options -Name $Name 2&gt;&amp;1\r\n            }\r\n        }\r\n        \r\n        # If an error is received it will have an exception property, the function will exit with that error information.\r\n        if ($NinjaPropertyOptions.Exception) { throw $NinjaPropertyOptions }\r\n        \r\n        # The below type's require values not typically given in order to be set. The below code will convert whatever we're given into a format ninjarmm-cli supports.\r\n        switch ($Type) {\r\n            \"Checkbox\" {\r\n                # While it's highly likely we were given a value like \"True\" or a boolean datatype it's better to be safe than sorry.\r\n                $NinjaValue = [System.Convert]::ToBoolean($Value)\r\n            }\r\n            \"Date or Date Time\" {\r\n                # Ninjarmm-cli expects the  Date-Time to be in Unix Epoch time so we'll convert it here.\r\n                $Date = (Get-Date $Value).ToUniversalTime()\r\n                $TimeSpan = New-TimeSpan (Get-Date \"1970-01-01 00:00:00\") $Date\r\n                $NinjaValue = $TimeSpan.TotalSeconds\r\n            }\r\n            \"Dropdown\" {\r\n                # Ninjarmm-cli is expecting the guid of the option we're trying to select. So we'll match up the value we were given with a guid.\r\n                $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header \"GUID\", \"Name\"\r\n                $Selection = $Options | Where-Object { $_.Name -eq $Value } | Select-Object -ExpandProperty GUID\r\n        \r\n                if (-not $Selection) {\r\n                    throw [System.ArgumentOutOfRangeException]::New(\"Value is not present in dropdown\")\r\n                }\r\n        \r\n                $NinjaValue = $Selection\r\n            }\r\n            default {\r\n                # All the other types shouldn't require additional work on the input.\r\n                $NinjaValue = $Value\r\n            }\r\n        }\r\n        \r\n        # We'll need to set the field differently depending on if its a field in a Ninja Document or not.\r\n        if ($DocumentName) {\r\n            $CustomField = Ninja-Property-Docs-Set -AttributeName $Name -AttributeValue $NinjaValue @DocumentationParams 2&gt;&amp;1\r\n        }\r\n        else {\r\n            $CustomField = Ninja-Property-Set -Name $Name -Value $NinjaValue 2&gt;&amp;1\r\n        }\r\n        \r\n        if ($CustomField.Exception) {\r\n            throw $CustomField\r\n        }\r\n    }\r\n\r\n    $ExitCode = 0\r\n}\r\nprocess {\r\n    # Error out if local administrator rights are not present.\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Host \"[Error] Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    # Initialize generic lists.\r\n    $SearchJobs = New-Object System.Collections.Generic.List[object]\r\n    $CustomFieldValue = New-Object System.Collections.Generic.List[string]\r\n\r\n    # For each given path to search, create a PowerShell job with the provided parameters.\r\n    $PathsToSearch | ForEach-Object {\r\n        $SearchJobs.Add(\r\n            (\r\n                Start-Job -ScriptBlock {\r\n                    param($SearchPath, $FileOrFolder, $SearchType)\r\n                    # We're going to wildcard search either files or folders depending on the parameters given.\r\n                    switch ($SearchType) {\r\n                        \"Files and Folders\" {\r\n                            Get-ChildItem -Path $SearchPath -Filter \"*$FileOrFolder*\" -Recurse | Select-Object -Property FullName, Attributes | ConvertTo-Csv\r\n                        }\r\n                        \"Folders Only\" {\r\n                            Get-ChildItem -Path $SearchPath -Filter \"*$FileOrFolder*\" -Recurse -Directory | Select-Object -Property FullName, Attributes | ConvertTo-Csv\r\n                        }\r\n                        \"Files Only\" { \r\n                            Get-ChildItem -Path $SearchPath -Filter \"*$FileOrFolder*\" -Recurse -File | Select-Object FullName, Attributes | ConvertTo-Csv\r\n                        }\r\n                    }\r\n                } -ArgumentList $_, $FileOrFolder, $SearchType\r\n            )\r\n        )\r\n    }\r\n\r\n    # Convert timeout to seconds as Wait-Job requires seconds.\r\n    $TimeoutInSeconds = $Timeout * 60\r\n    $StartTime = Get-Date\r\n\r\n    # Wait for all jobs to complete or timeout.\r\n    foreach ($SearchJob in $SearchJobs) {\r\n        # Calculate the remaining time.\r\n        $TimeElapsed = (Get-Date) - $StartTime\r\n        $RemainingTime = $TimeoutInSeconds - $TimeElapsed.TotalSeconds\r\n    \r\n        # If there is no remaining time, break the loop.\r\n        if ($RemainingTime -le 0) {\r\n            break\r\n        }\r\n    \r\n        # Wait for the current job with the remaining time as the timeout.\r\n        $SearchJob | Wait-Job -Timeout $RemainingTime | Out-Null\r\n    }\r\n\r\n    # Output a warning if the job fails to complete.\r\n    $IncompleteJobs = $SearchJobs | Get-Job | Where-Object { $_.State -eq \"Running\" }\r\n    if ($IncompleteJobs) {\r\n        Write-Host \"[Error] The timeout period of $Timeout minutes has been reached, but not all files or directories have been searched!\"\r\n        $CustomFieldValue.Add(\"[Error] The timeout period of $Timeout minutes has been reached, but not all files or directories have been searched!\")\r\n        $ExitCode = 1\r\n    }\r\n\r\n    # Our PowerShell Job outputs in CSV format; we'll convert it here.\r\n    $MatchingItems = $SearchJobs | ForEach-Object {\r\n        $_ | Get-Job | Receive-Job -ErrorAction SilentlyContinue -ErrorVariable JobErrors | ConvertFrom-Csv\r\n    }\r\n\r\n    # Identify whether or not we have a match for a file or folder here.\r\n    $FileMatch = $MatchingItems | Where-Object { $_.Attributes -ne \"Directory\" }\r\n    $FolderMatch = $MatchingItems | Where-Object { $_.Attributes -eq \"Directory\" }\r\n\r\n    # If we have a match for a file we'll output that here.\r\n    if ($FileMatch) { \r\n        Write-Host -Object \"[Alert] File Found.\"\r\n        $CustomFieldValue.Add(\"[Alert] File Found.\")\r\n    }\r\n\r\n    # If we have a match for a folder we'll output that here.\r\n    if ($FolderMatch) { \r\n        Write-Host -Object \"[Alert] Folder Found.\" \r\n        $CustomFieldValue.Add(\"[Alert] Folder Found.\")\r\n    }\r\n\r\n    # If we have no matches we'll output that here.\r\n    if (-not $FileMatch -and -not $FolderMatch) {\r\n        Write-Host -Object \"Unable to find $FileOrFolder.\"\r\n        $CustomFieldValue.Add(\"Unable to find $FileOrFolder.\")\r\n    }\r\n\r\n    # For each matching file we'll output their full path.\r\n    $MatchingItems | ForEach-Object { \r\n        Write-Host \"$($_.FullName)\"\r\n        $CustomFieldValue.Add(\"$($_.FullName)\") \r\n    }\r\n\r\n    # Output any failures or errors received.\r\n    $FailedJobs = $SearchJobs | Get-Job | Where-Object { $_.State -ne \"Completed\" -and $_.State -ne \"Running\" }\r\n    if ($FailedJobs -or $JobErrors) {\r\n        Write-Host \"\"\r\n        Write-Host \"[Error] Failed to search certain files or directories due to an error.\"\r\n\r\n        $CustomFieldValue.Add(\"\")\r\n        $CustomFieldValue.Add(\"[Error] Failed to search certain files or directories due to an error.\")\r\n        if ($JobErrors) {\r\n            Write-Host \"\"\r\n            $CustomFieldValue.Add(\"\")\r\n\r\n            $JobErrors | ForEach-Object { \r\n                Write-Host \"[Error] $($_.Exception.Message)\" \r\n                $CustomFieldValue.Add(\"[Error] $($_.Exception.Message)\")\r\n            }\r\n        }\r\n        $ExitCode = 1\r\n    }\r\n\r\n    $SearchJobs | Get-Job | Remove-Job -Force\r\n\r\n    # Attempt to set the custom field using the Set-NinjaProperty function, if provided.\r\n    if ($CustomField) {\r\n        try {\r\n            Write-Host \"Attempting to set Custom Field '$CustomField'.\"\r\n            Set-NinjaProperty -Name $CustomField -Value ($CustomFieldValue | Out-String)\r\n            Write-Host \"Successfully set Custom Field '$CustomField'!\"\r\n        }\r\n        catch {\r\n            if (-not $_.Exception.Message) {\r\n                Write-Host \"[Error] $($_.Message)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Error] $($_.Exception.Message)\"\r\n            }\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n\r\n    exit $ExitCode\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Greifen Sie auf \u00fcber 300 Skripte im NinjaOne Dojo zu.<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/de\/kostenlosetestversionformular\/\">Zugang erhalten<\/a><\/p>\n<\/div>\n<h2>Detailansicht<\/h2>\n<p>Das Skript arbeitet in mehreren Stufen, die alle zur Gesamtfunktionalit\u00e4t beitragen. Hier ist eine schrittweise Aufschl\u00fcsselung:<\/p>\n<p><strong>1. Initialisierung der Parameter<\/strong>: Das Skript beginnt mit der Definition mehrerer Parameter:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"2\">SearchPath: Die zu durchsuchenden Verzeichnisse.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"2\">FileOrFolder: Der Name der Datei oder des Ordners, nach dem gesucht werden soll.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"2\">SearchType: Ob nach Dateien, Ordnern oder beidem gesucht werden soll.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"2\">Timeout: Die maximale Dauer f\u00fcr die Suche.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"2\">CustomField: Ein optionales Feld zur Erfassung von Suchergebnissen.<\/li>\n<\/ul>\n<p><strong>2. \u00dcberschreibung durch Umgebungsvariablen<\/strong>: Das Skript pr\u00fcft, ob Umgebungsvariablen gesetzt sind, die die Eingabeparameter \u00fcberschreiben sollen. Dies erm\u00f6glicht eine dynamische Anpassung an unterschiedliche Umgebungen.<\/p>\n<p><strong>3. Validierung<\/strong>: Das Skript f\u00fchrt mehrere Validierungspr\u00fcfungen durch:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"2\">Stellt sicher, dass ein Suchpfad angegeben wird.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"2\">Validiert und formatiert den Suchpfad.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"2\">\u00dcberpr\u00fcft die Existenz der angegebenen Pfade.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"9\" data-aria-level=\"2\">Validiert den Datei- oder Ordnernamen.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"10\" data-aria-level=\"2\">Gew\u00e4hrleistet, dass der Timeout-Wert innerhalb eines akzeptablen Bereichs liegt.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"11\" data-aria-level=\"2\">Best\u00e4tigt, dass der Suchtyp g\u00fcltig ist.<\/li>\n<\/ul>\n<p><strong>4. Pr\u00fcfung auf Administratorrechte<\/strong>: Das Skript enth\u00e4lt eine Funktion, die \u00fcberpr\u00fcft, ob es mit Administratorrechten ausgef\u00fchrt wird, was f\u00fcr bestimmte Dateioperationen erforderlich ist.<\/p>\n<p><strong>5. Ausf\u00fchrung der Suche<\/strong>: Die Kernfunktionalit\u00e4t umfasst die Erstellung von PowerShell-Jobs f\u00fcr jeden zu durchsuchenden Pfad. Diese jobs f\u00fchren rekursive Suchen auf der Grundlage der angegebenen Parameter durch und geben die Ergebnisse im CSV-Format zur\u00fcck.<\/p>\n<p><strong>6. Handhabung der Ergebnisse<\/strong>: Das Skript sammelt und verarbeitet die Suchergebnisse:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"12\" data-aria-level=\"2\">Identifiziert \u00dcbereinstimmungen mit Dateien und Ordnern.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"13\" data-aria-level=\"2\">Gibt die vollst\u00e4ndigen Pfade aller \u00fcbereinstimmenden Elemente aus.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:1440,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"14\" data-aria-level=\"2\">Protokolliert Fehler oder unvollst\u00e4ndige Suchen.<\/li>\n<\/ul>\n<p><strong>7. Einstellung der benutzerdefinierten Felder<\/strong>: Wenn ein benutzerdefiniertes Feld angegeben ist, versucht das Skript, es mit den Suchergebnissen auszuf\u00fcllen, wobei eine Hilfsfunktion verwendet wird, um mit verschiedenen Feldtypen umzugehen.<\/p>\n<p><strong>8. Fehlerbehandlung und Bereinigung<\/strong>: Das Skript sorgt daf\u00fcr, dass alle Fehler protokolliert und alle Jobs ordnungsgem\u00e4\u00df bereinigt werden, bevor es mit einem entsprechenden Exit-Code beendet wird.<\/p>\n<h2>Potenzielle Anwendungsf\u00e4lle<\/h2>\n<p>Stellen Sie sich ein Szenario vor, in dem ein IT-Experte ein Netzwerk von Workstations f\u00fcr einen Firmenkunden verwaltet. Er muss im Rahmen einer Sicherheits\u00fcberpr\u00fcfung gew\u00e4hrleisten, dass sich in den Benutzerverzeichnissen keine nicht autorisierten ausf\u00fchrbaren Dateien befinden. Durch den Einsatz dieses Skripts kann die Suche auf allen Workstations automatisiert werden, sodass alle nicht autorisierten Dateien schnell identifiziert und bei Bedarf Ma\u00dfnahmen ergriffen werden k\u00f6nnen. Diese Automatisierung erh\u00f6ht nicht nur die Sicherheit, sondern verschafft dem IT-Team auch wertvolle Zeit, um sich auf strategischere Aufgaben zu konzentrieren.<\/p>\n<h2>Vergleiche<\/h2>\n<p>Dieses Skript bietet einen umfassenden und automatisierten Ansatz f\u00fcr die Datei- und Ordnersuche im Vergleich zu manuellen Methoden oder einfachen Batch-Skripten. Herk\u00f6mmliche Methoden bestehen h\u00e4ufig in dem manuellen Navigieren in Verzeichnissen oder in der Verwendung einfacher Skripte, denen fortgeschrittene Funktionen wie die Behandlung von Zeit\u00fcberschreitungen, die Erfassung in benutzerdefinierten Feldern und die Ausf\u00fchrung von Multi-Threaded-Jobs fehlen. Die F\u00e4higkeit des PowerShell-Skripts, komplexe Umgebungen zu handhaben und detaillierte Ausgaben zu liefern, macht es zu einer hervorragenden Wahl f\u00fcr IT-Experten.<\/p>\n<h2>FAQs<\/h2>\n<h3>1) Wie kann ich mehrere Verzeichnisse f\u00fcr die Suche angeben?<\/h3>\n<p>Verwenden Sie eine durch Komma getrennte Liste f\u00fcr den Parameter &#8218;SearchPath&#8216;, z. B. &#8218;C:\\Path1,C:\\Path2&#8216;.<\/p>\n<h3>2) Kann ich die Suche nur auf Dateien oder nur auf Ordner beschr\u00e4nken?<\/h3>\n<p>Ja, verwenden Sie den Parameter &#8218;SearchType&#8216; mit den Werten &#8218;Files Only&#8216; oder &#8218;Folders Only&#8216;.<\/p>\n<h3>3) Was passiert, wenn die Suche das angegebene Timeout \u00fcberschreitet?<\/h3>\n<p>Das Skript bricht alle unvollst\u00e4ndigen Suchvorg\u00e4nge ab und gibt eine Fehlermeldung aus.<\/p>\n<h3>4) Ben\u00f6tige ich Administratorrechte, um dieses Skript auszuf\u00fchren?<\/h3>\n<p>Ja, das Skript pr\u00fcft, ob Sie \u00fcber Administratorrechte verf\u00fcgen, und wird beendet, wenn es nicht mit ausreichenden Rechten ausgef\u00fchrt wird.<\/p>\n<h2>Folgen<\/h2>\n<p>Die Ergebnisse dieses Skripts haben erhebliche Auswirkungen auf die IT-Sicherheit. Durch die Identifizierung nicht autorisierter oder verlegter Dateien und Ordner k\u00f6nnen IT-Experten sofort Ma\u00dfnahmen ergreifen, um potenzielle Sicherheitsrisiken zu minimieren. Die regelm\u00e4\u00dfige Ausf\u00fchrung dieses Skripts als Teil einer Wartungsroutine kann dazu beitragen, die Einhaltung von Unternehmensrichtlinien und gesetzlichen Vorschriften zu gew\u00e4hrleisten und damit die allgemeine Sicherheitslage zu verbessern.<\/p>\n<h2>Empfehlungen<\/h2>\n<p>Beachten Sie bei der Verwendung dieses Skripts die folgenden Best Practices:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\">Aktualisieren Sie das Skript regelm\u00e4\u00dfig, um es an \u00c4nderungen in Ihrer Umgebung anzupassen.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\">Integrieren Sie das Skript in automatisierte Wartungsroutinen.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\">\u00dcberpr\u00fcfen Sie die Suchergebnisse und handeln Sie umgehend, um die Sicherheit zu garantieren.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\">Passen Sie die Skriptparameter an spezifische Anforderungen und Umgebungen an.<\/li>\n<\/ul>\n<h2>Abschlie\u00dfende \u00dcberlegungen<\/h2>\n<p>Dieses PowerShell-Skript ist ein leistungsstarkes Tool f\u00fcr IT-Experten, das automatisierte und effiziente Datei- und Ordnersuchfunktionen bietet. Durch den Einsatz dieses Skripts k\u00f6nnen IT-Teams ihre <a href=\"https:\/\/www.ninjaone.com\/de\/effizienz\/\" target=\"_blank\" rel=\"noopener\">betriebliche Effizienz<\/a> steigern, <a href=\"https:\/\/www.ninjaone.com\/de\/top-5-it-sicherheitsgrundlagen\/\" target=\"_blank\" rel=\"noopener\">die Sicherheit aufrechterhalten<\/a> und f\u00fcr die Einhaltung von Unternehmensrichtlinien sorgen. Die Integration des Skripts in NinjaOne kann die Verwaltungsaufgaben weiter rationalisieren und eine zentrale Steuerung und \u00dcberwachung \u00fcber mehrere Endpunkte hinweg erm\u00f6glichen.<\/p>\n","protected":false},"author":35,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4383],"class_list":["post-385089","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub\/385089","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/comments?post=385089"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/media?parent=385089"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/operating_system?post=385089"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/de\/wp-json\/wp\/v2\/use_cases?post=385089"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}