将ObjectGuid从AD转换为GUID Powershell [英] Convert ObjectGuid from AD to GUID powershell

查看:51
本文介绍了将ObjectGuid从AD转换为GUID Powershell的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么这在PowerShell v4中不起作用:

I cannot understand why this does not work in PowerShell v4:

New-Object -TypeName System.Guid((New-Object -TypeName DirectoryServices.DirectorySearcher -Property @{ Filter = "(&(objectCategory=computer)(name=$env:COMPUTERNAME))" }).FindOne().Properties.Item('objectguid')[0])

在PowerShell v5中可以使用的情况:

when this works in PowerShell v5:

[Guid]::New((New-Object -TypeName DirectoryServices.DirectorySearcher -Property @{ Filter = "(&(objectCategory=computer)(name=$env:COMPUTERNAME))" }).FindOne().Properties.Item('ObjectGuid')[0])

但是不幸的是,PowerShell v4中不存在"New"方法.但是,第一个示例应该起作用.arg是一个字节数组,因为它应该接受:

But unfortantly the 'New' method does not exist in PowerShell v4. But, the first example should work. the arg is a Byte Array, as the it should accept: GUID MSDN. But i get an error that says:

Cannot find an overload for "Guid" and the argument count: "16"

我们非常感谢您的帮助.谢谢!

Any help is much appreciated. Thanks!

推荐答案

我可以使用它,必须使用了错误的构造函数吗?我不知道,但这可行:

I got it to work, must have been using the wrong constructor? i don't know but this works:

New-Object -TypeName System.Guid -ArgumentList @(,(New-Object -TypeName DirectoryServices.DirectorySearcher -Property @{ Filter = "(&(objectCategory=computer)(name=$env:COMPUTERNAME))" }).FindOne().Properties.Item('objectguid')[0])

希望它可以在某个时间,某个地方为某人提供帮助.

Hope it helps someone, sometime, somewhere.

这篇关于将ObjectGuid从AD转换为GUID Powershell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆