Powershell / WScript创建快捷方式如果不存在

问题描述

我想知道是否有人可以帮助我?我在网上找到了一些Powershell脚本,这些脚本可以使$ source到$ destination成为捷径。但是,它似乎每次都被覆盖,我只希望它在new上创建一个.lnk。

该脚本的原始来源为here,这是我当前的“不工作”脚本。.我添加了以下内容,但似乎不起作用。我想我需要以某种方式获取它来检查$ destination,然后在$ file.lnk不存在的情况下继续

If ($status -eq $false) {($WshShell.fso.FileExists("$Destination") + "*.lnk")

完整脚本:

    function Create-ShortcutForEachFile {

    Param(
        [ValidateNotNullOrEmpty()][string]$Source,[ValidateNotNullOrEmpty()][string]$Destination,[switch]$Recurse
    )

    # set recurse if present
    if ($Recurse.IsPresent) { $splat = @{ Recurse = $true } }

    # Getting all the source files and source folder
    $gci = gci $Source @splat
    $Files = $gci | ? { !$_.PSisContainer }
    $Folders = $gci | ? { $_.PsisContainer }

    # Creating all the folders
    if (!(Test-Path $Destination)) { mkdir $Destination -ea SilentlyContinue > $null }
    $Folders | % {
        $Target = $_.FullName -replace [regex]::escape($Source),$Destination
        mkdir $Target -ea SilentlyContinue > $null
    }

    # Creating Wscript object
    $WshShell = New-Object -comObject WScript.Shell

    # Creating all the Links
    If ($status -eq $false) {($WshShell.fso.FileExists("$Destination") + "*.lnk")

      $Files | % {
          $InkName = "{0}.lnk" -f $_.sBaseName
          $Target = ($_.DirectoryName -replace [regex]::escape($Source),$Destination) + "\" + $InkName
          $Shortcut = $WshShell.CreateShortcut($Target)
          $Shortcut.TargetPath = $_.FullName
          $Shortcut.Save()
          }
        }
}
Create-ShortcutForEachFile -Source \\myserver.domain.local\Folder1\Folder2\Test -Destination \\myserver2.domain.local\Folder1\Folder2\Test -Recurse

希望任何人都可以帮助我,为成为PowerShell /脚本新手而道歉。

解决方法

我的兄弟好心地重新编写了脚本,以更好地满足我的需求。

这里是:

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.1/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.1/umd/react-dom.production.min.js"></script>