Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
意外标记';}';表达式或语句中的PowerShell_Powershell_Sharepoint - Fatal编程技术网

意外标记';}';表达式或语句中的PowerShell

意外标记';}';表达式或语句中的PowerShell,powershell,sharepoint,Powershell,Sharepoint,大家好,我正在为Powershell使用一个脚本。这是发生错误的部分原因:在我添加自动文件命名(按日期命名)之前,它工作正常,所以我想问题就在这里。感谢您的帮助 foreach ($web in $site.AllWebs) { #Write the Header to "Tab Separated Text File" "$($web.title) `t $($web.URL) `t `t `t `t " | out-file "c:\users_Permision

大家好,我正在为Powershell使用一个脚本。这是发生错误的部分原因:在我添加自动文件命名(按日期命名)之前,它工作正常,所以我想问题就在这里。感谢您的帮助

  foreach ($web in $site.AllWebs)
  {
    #Write the Header to "Tab Separated Text File"
    "$($web.title) `t $($web.URL) `t  `t  `t `t " | out-file "c:\users_PermisionReport + (date -f yyyy-MM-dd) + "-DSR.csv" -append
     #Get all Groups and Iterate through   
     foreach ($group in $Web.groups)
     {
            "`t  `t $($Group.Name) `t   `t `t " | out-file "c:\users_PermisionReport + (date -f yyyy-MM-dd) + "-DSR.csv" -append
            #Iterate through Each User in the group
                   foreach ($user in $group.users)
                    {
                       #Exclude Built-in User Accounts
                if(($User.LoginName.ToLower() -ne "nt authority\authenticated users") -and ($User.LoginName.ToLower() -ne "sharepoint\system") -and ($User.LoginName.ToLower() -ne "nt authority\local service"))
                {
                            "`t  `t  `t  $($user.LoginName)  `t  $($user.name) `t  $($user.Email)" | out-file "c:\users_PermisionReport" + (date -f yyyy-MM-dd) + "-DSR.csv" -append 
}
}
}
}//Error is here.
#错误消息:

 Unexpected token '}' in expression or statement.
 CategoryInfo          : ParserError: (:) [], ParseException
 FullyQualifiedErrorId : UnexpectedToken

对于包含此代码的任何行:

"c:\users_PermisionReport" + (date -f yyyy-MM-dd) + "-DSR.csv"
将其替换为以下代码: 这将在文件名后附加一个日期,以避免重复或删除旧文件。
这在不更改任何其他内容的情况下解决了错误。

使用此源代码格式,我并不奇怪很难发现错误。请正确设置问题中的代码格式,在此过程中,您可以自己发现错误。请注意,问题结束的标准原因之一是:“寻求调试帮助的问题(“为什么此代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中复制它所需的最短代码。”这基本上是一个可能结束的打字问题。如果你遵循一些块的编码准则,你会发现这一点。如果它是一个打字错误,请指出它,因为我清楚地指出了错误。但是,我刚刚更改了文件名行后面的日期,效果很好。谢谢你没有帮助Matt和mklemnt。是的,我可以看到错误在哪里。我想说的是,如果您遵循一些代码指导原则,特别是当涉及到块时,那么您将知道您可能有一个额外的括号。为了解决这个问题,你需要把收尾大括号和收尾大括号对齐。它并没有成为一个伟大的问题,因为它归结为一个错误。我想让你自己去修。这里还有未关闭的字符串。我会使用
(“c:\users\u permissionreport{0:yyyy-MM-dd}-DSR.csv”-f(get-date))
,但这是一个品味/个人偏好的问题,与主题无关。
"c:\users_PermisionReport $(get-date -f yyyy-MM-dd).csv"