首页 > 解决方案 > Powershell 4.0 - 新的 GUID 生成问题

问题描述

当尝试在脚本下运行时,我收到以下错误消息。我正在使用 Powershell 4.0

错误:

Method invocation failed because [System.Guid] does not contain a method named 'new'.
At line:13 char:3
+         $ObjectGUID = [guid]::new($ADObject)
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodNotFound

脚本 :

$Identity = "user01"

        try
        {
            $ADObject = ([adsisearcher]"samAccountName=$Identity").FindOne() | foreach {$_.GetDirectoryEntry() | Select-Object -ExpandProperty ObjectGUID}
        }
        catch
        {
            Write-Error -Message "Error while querying $Identity"
            Break
        }
        
        $ObjectGUID = [guid]::new($ADObject)

标签: powershell

解决方案


推荐阅读