我试图通过powershell将整数(或字符串中的数字)转换为guid,我已经使用了下面的方法,但找不到其他方法。这是完全可能的吗?
$myId = [System.Guid]::Parse("123456789")
Exception calling "Parse" with "1" argument(s): "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."
当我在解析函数中不使用引号,仅使用数字时,也会发生同样的情况。
发布于 2017-07-21 18:05:26
试一试
$myId = [System.Guid]::Parse("12345678-1234-1234-1234-123456789123")
$myId | gm
TypeName: System.Guid
发布于 2018-12-07 05:00:35
下面是一种更动态的方法,它考虑了表示整数的字符串的长度
$foo = 123456
[System.Guid]::Parse("0"*(32-$foo.ToString().Length) + $foo.ToString())
https://stackoverflow.com/questions/45234724
复制相似问题