【问题标题】:Unexpected token 'server' in expression or statement表达式或语句中出现意外的令牌“服务器”
【发布时间】:2014-06-22 05:38:01
【问题描述】:
$ServerList = Get-Content "C:\Users\munjanga\Desktop\Execute\Testing\servers.txt"
$ServerList

$Header="FolderPath,IdentityReference,AccessControlType,IsInherited,InheritedFlags,PropagationFlags"

Add-Content -Value $Header -Path $Output

Foreach ($Server in $ServerList) {
    $output = "\\C:\Users\munjanga\Desktop\Repositroy "$server.output.csv"
    Del $Output -ErrorAction SilentlyContinue

    $RootPath ="\\$Server\C:\system.sav"

    $Folders = dir $RootPath -recurse | where {$_.psiscontainer -eq $true} -ErrorAction SilentlyContinue

    Add-Content -Value "$Header" -Path $Output

    Foreach ($Folder in $Folders){

        $ACLs = get-acl $Folder.fullname | ForEach-Object { $_.Access }

        Foreach ($ACL in $ACLs){

            $OutInfo = $Folder.Fullname + "," + $ACL.IdentityReference + "," + $ACL.AccessControlType + "," + $ACL.IsInherited + "," + $ACL.InheritanceFlags + "," + $ACL.PropagationFlags

            Add-Content -Value $OutInfo -Path $output -ErrorAction SilentlyContinue
       }
    }
}

【问题讨论】:

    标签: powershell syntax-error


    【解决方案1】:

    您在这一行有一个格式错误的字符串文字:

    $output = "\\C:\Users\munjanga\Desktop\Repositroy "$server.output.csv"
                                                    --^
    

    上面指出的" 不应该存在。我想你的意思是写:

    $output = "\\C:\Users\munjanga\Desktop\Repositroy\$server.output.csv"
    

    字符串开头的双斜杠也可能不正确。也许它应该被删除:

    $output = "C:\Users\munjanga\Desktop\Repositroy\$server.output.csv"
    

    【讨论】:

    • 谢谢你帮助我克服了这个问题,但现在我得到了:“cmdlet where Object at command pipeline position 1. 为以下参数提供值:Filterscript:” 它不像错误那样出现一个请求,所以我想知道它是否要求输入实际的服务器?我正在我的虚拟机中运行测试,所以我不知道这是否会导致这种情况,因为我在技术上只有 1 个“服务器”,有人可以建议吗?
    猜你喜欢
    • 1970-01-01
    • 2018-05-04
    • 2022-11-04
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多