无法在此对象上找到属性“名称”。验证该属性是否存在

时间:2017-12-26 14:10:48

标签: powershell

我的脚本正在运行,但我收到此错误:

  

在此对象上找不到属性“名称”。验证该属性是否存在。

我正在循环复制文件夹。知道发生了什么事吗?

    $source50 = "c:\folder\"
    $destination50 = "c:\folder1\"

    for ($i = 1; $i -le 7; $i++) {
        $d = ((Get-Date).AddDays( + $i))
        $d2 = $d.ToString("yyyy-MM-dd")
        $v = Get-ChildItem $source50 -Recurse -Include "$d2"
 foreach ($file in $v) 
      {

               if ( Test-Path  $v.FullName)


                 {  
                    if (-not (Test-Path -Path $destination50$d4)){
                    New-Item -ItemType directory -Path $destination50$d4 

                    }


                     Write-Output "Copy ok " $v.FullName     
                     $bd= Copy-Item $v.FullName -Destination $destination50$d4 
                     break 


                  }

       }

代码给出错误:

ok C:\folder\2017-12-27
ok C:\folder\2017-12-28
The property 'Name' cannot be found on this object. Verify that the property
exists.
At line:16 char:11
+       if ($v.Name -eq $d2) {
+           ~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

ok C:\folder\2017-12-30
The property 'Name' cannot be found on this object. Verify that the property
exists.

1 个答案:

答案 0 :(得分:0)

$ v.Name抛出异常,因为它是一个数组对象,而不是“System.IO”。具有属性名称。

尝试使用此代码:

//get 59th second of this minute and start an observable timer
var  date : Date = moment().endOf('minute').toDate();
const source = Observable.timer(date, 60000);

source.subscribe(val => console.log("New Minute: " + moment().format()));