Powershell LocalBackup New-PSDrive 目标故障

用户11414173

当我查看日志文件时,我想从服务器备份到本地 bu,它从 New-PSDrive 给出错误。

LocalBackup 文件中的错误部分:

挂载备份源

New-PSDrive :指定的驱动器根目录“B”不存在,或者不是文件夹。

在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:57 char:5 + New-PSDrive -Name $BkpSrc[0] -Root $BkpSrc[1] -PSProvider FileSys ... + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ + CategoryInfo : ReadError: (S:PSDriveInfo) [New-PSDrive], IOException +fullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand

New-PSDrive : 指定的驱动器根目录 ":" 要么不存在,要么不是文件夹。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:57 char:5 + New-PSDrive -Name $BkpSrc[0] -Root $BkpSrc[1] -PSProvider FileSys ... + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ + CategoryInfo : ReadError: (C:PSDriveInfo) [New-PSDrive], IOException +fullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand

挂载备份目的地

New-PSDrive :指定的驱动器根目录“B”不存在,或者不是文件夹。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:62 char:5 + New-PSDrive -Name $BkpDst[0] -Root $BkpDst[1] -PSProvider FileSys ... + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ + CategoryInfo : ReadError: (S:PSDriveInfo) [New-PSDrive], IOException +fullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand

New-PSDrive : 指定的驱动器根目录 ":" 要么不存在,要么不是文件夹。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:62 char:5 + New-PSDrive -Name $BkpDst[0] -Root $BkpDst[1] -PSProvider FileSys ... + ~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ + CategoryInfo : ReadError: (C:PSDriveInfo) [New-PSDrive], IOException +fullyQualifiedErrorId : DriveRootError,Microsoft.PowerShell.Commands.NewPSDriveCommand

错误:未指定目标目录。

   Simple Usage :: ROBOCOPY source destination /MIR

         source :: Source Directory (drive:\path or \\server\share\path).
    destination :: Destination Dir  (drive:\path or \\server\share\path).
           /MIR :: Mirror a complete directory tree.

For more usage information run ROBOCOPY /?

**** /MIR 可以删除和复制文件!

**** /MIR 可以删除和复制文件!

卸载备份源

Remove-PSDrive:找不到驱动器。名称为“S”的驱动器不存在。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:81 char:5 + Remove-PSDrive -Name $BkpSrc[0] *>>$LogPath/$Logfile + ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (S:String) [移除-PSDrive], DriveNotFoundException +fullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand

Remove-PSDrive:无法删除驱动器“C”,因为它正在使用中。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:81 char:5 + Remove-PSDrive -Name $BkpSrc[0] *>>$LogPath/$Logfile + ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-PSDrive ], PSInvalidOperationException +fullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemovePSDriveCommand

卸载备份源

Remove-PSDrive:找不到驱动器。名称为“S”的驱动器不存在。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:86 char:5 + Remove-PSDrive -Name $BkpDst[0] *>>$LogPath/$Logfile + ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (S:String) [移除-PSDrive], DriveNotFoundException +fullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.RemovePSDriveCommand

Remove-PSDrive:无法删除驱动器“C”,因为它正在使用中。在 C:\Temp\trying2adm_trerulug\Untitled2.ps1:86 char:5 + Remove-PSDrive -Name $BkpDst[0] *>>$LogPath/$Logfile + ~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Remove-PSDrive ], PSInvalidOperationException +fullyQualifiedErrorId : InvalidOperation,Microsoft.PowerShell.Commands.RemovePSDriveCommand

我是从 Internet 搜索的系统中的管理员,并绕过执行策略和凭据,它看起来不错,但仍然无法正常工作。

代码部分:

 # @(DstName,Path)

 $BackupDestinations =   @(

 , @('Batch','\\srvr0001\TEMP\trying3')

 , @('test2','\\srvr0002\TEMP\trying2')
                          )
 # @(SrcName,Path,DstName)
 $BackupSources = @(
 , @('abcde','C:\Temp\ProjectCopy\Backup\Archives\Batch','Batch')
 , @('defgh','C:\Temp\Project - Copy\Backup\Archives\WinCCTag','test2')
                   )
 $LogPath = "C:\Temp\trying2adm_trerulug"

 $LogVersion = 50

 If (-Not (Test-Path $LogPath)){mkdir $LogPath}
 While ($LogVersion -gt 0)
 {
 $OldLogfile = "LocalBackup.$LogVersion.log"
 $Logfile = "LocalBackup.$($LogVersion-1).log"

 Copy-Item -Path $LogPath\$Logfile -Destination $LogPath\$OldLogFile -

 ErrorAction SilentlyContinue

 $LogVersion-- 

 }
 echo $null > $LogPath\$Logfile

 Function Write-Log{

 Param([string]$logstring)

 # Write-Host $LogPath\$LogFile

 Add-Content -Path $LogPath\$LogFile $logstring

 }

 $RoboArgs = 
 $("/E","/Z","/COPY:DAT","/R:3","/W:10","/XN","/XO","/XX","/NP")

 # Mount PSDrives
 ## Backup Sources
 Write-Log "### Mount Backup Sources ##########################"

 Foreach($BkpSrc in $BackupSources){

 New-PSDrive -Name $BkpSrc[0] -Root $BkpSrc[1] -PSProvider FileSystem 

 *>>$LogPath/$Logfile
 }
 ## Backup Destinations

 Write-Log "### Mounting Backup Destinations ##################"

 Foreach($BkpDst in $BackupDestinations){

 New-PSDrive -Name $BkpDst[0] -Root $BkpDst[1] -PSProvider FileSystem 

 *>>$LogPath/$Logfile
 }

 # Copy Backups

 Write-Log "### Start copyjobs ################################"

 Foreach($BkpSrc in $BackupSources){

 # Select right source directory

 Foreach($BkpDst in $BackupDestinations){

 if ($BkpDst[0] -eq $BkpSrc[2]){

 $BkpDstPath = $BkpDst[1]
 }
 }
 robocopy $BkpSrc[1] $BkpDstPath $RoboArgs *>>$LogPath/$Logfile
 }

 # Unmount the PSDrives

 ## Backup Sources

 Write-Log "### Unmount Backup Sources ########################"

 Foreach($BkpSrc in $Backupsources){

 Remove-PSDrive -Name $BkpSrc[0] *>>$LogPath/$Logfile

 }
 ## Backup Destinations

 Write-Log "### Unmount Backup Sources ########################"

 Foreach($BkpDst in $BackupDestinations){

 Remove-PSDrive -Name $BkpDst[0] *>>$LogPath/$Logfile

 }
Lee_Daley

您的问题是由您构建$BackupDestinations&$BackupSources集合的方式引起的你没有数组数组……你有一个字符串数组。循环中$BckSrc[0]当前项目的第一个字母也是如此foreach[咧嘴笑]

要么切换到使用哈希表,要么使用,数组运算符强制将子数组添加为子数组而不是项目列表。

如果你想坚持使用数组,请使用这样的东西 [注意每个子数组前的前导逗号] ...

$BackupSources = @(
    , @('abcde','C:\Temp\ProjectCopy\Backup\Archives\Batch','Batch')
    , @('defgh','C:\Temp\Project - Copy\Backup\Archives\WinCCTag','test2')
    )

使用以下代码,并且没有使用列表中名称的 PSDrive,并且目标目录已经创建 --- 没有关于创建或删除有问题的 PSDrive 的错误消息。

$BackupDestinations =   @(
, @('Batch','\\srvr0001\TEMP\trying3')
, @('test2','\\srvr0002\TEMP\trying2')
                        )

$BackupSources = @(
, @('abcde','C:\Temp\ProjectCopy\Backup\Archives\Batch','Batch')
, @('defgh','C:\Temp\Project - Copy\Backup\Archives\WinCCTag','test2')
                )

Foreach ($BkpSrc in $BackupSources)
    {
    New-PSDrive -Name $BkpSrc[0] -Root $BkpSrc[1] -PSProvider FileSystem #-WhatIf
    }

Get-PSDrive | Out-Host

'=' * 20 | Out-Host

#<#
Foreach ($BkpSrc in $Backupsources)
    {
    Remove-PSDrive -Name $BkpSrc[0]
    pause
    }
Get-PSDrive
#>

所以......你的代码的哪一部分产生了你在原始帖子中列出的错误?

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用New-PsDrive时Powershell作业卡住了

来自分类Dev

在Powershell中为PSDrive设置名称

来自分类Dev

New-PSDrive --Persist不起作用

来自分类Dev

模块内的New-PSDrive不起作用

来自分类Dev

模块内的New-PSDrive不起作用

来自分类Dev

无法在 powershell 中通过管道传输注册表项中的文件路径 - HKCU PSDrive

来自分类Dev

净使用* / delete / y无法解决错误“ New-PSDrive:与服务器的多个连接....”

来自分类Dev

DFS共享的New-PsDrive远程复制共享错误:指定的登录会话不存在

来自分类Dev

New-PSDrive在脚本和控制台中的不同行为

来自分类Dev

Powershell DFS目标列表

来自分类Dev

Get-PSDrive选择格式

来自分类Dev

New-CryptographyKey 模块 Powershell

来自分类Dev

Powershell控制台导致脚本故障

来自分类Dev

无法从Get-PSDrive捕获DriveNotFoundException

来自分类Dev

Powershell New-WebServiceProxy异步方法

来自分类Dev

AzureAD PowerShell New-AzureRmRoleAssignment不断失败

来自分类Dev

Powershell New-NfsShare无效的名称空间

来自分类Dev

设置Powershell MS-Word MailMerge的目标

来自分类Dev

Powershell调用Web请求到多个目标

来自分类Dev

Powershell:复制项通配符目标路径

来自分类Dev

抑制灾难性Powershell进程故障的错误窗口

来自分类Dev

对厨师食谱中的Powershell脚本进行故障排除

来自分类Dev

使用new运算符后出现段故障

来自分类Dev

网格loadMask故障。设置loadMask目标配置

来自分类Dev

如何从System.IO.File调用访问PSDrive?

来自分类Dev

为什么测试路径为PSDrive返回$ false?

来自分类Dev

如何在2个PSDrive之间传输文件

来自分类Dev

如何使用PowerShell在New-ADUser中设置msTSInitialProgram?

来自分类Dev

将Powershell Psobject转换为New-object

Related 相关文章

热门标签

归档