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 方法调用失败。system.string错误_Powershell - Fatal编程技术网

Powershell 方法调用失败。system.string错误

Powershell 方法调用失败。system.string错误,powershell,Powershell,早上好 我正在尝试使用CSV文件和用户列表,并自动将AD users ExtensionAttribute 15设置回“notset”值 我使用类似的代码来填充属性,CSV文件只包含两个内容,用户LAN ID和属性值 填充字段不是问题,将值更改回“未设置”已被解决 这是我正在使用的代码 Import-module ActiveDirectory Import-CSV "code.csv" | % { $User = $_.cn $user.Put(“extensionAttribute1

早上好

我正在尝试使用CSV文件和用户列表,并自动将AD users ExtensionAttribute 15设置回“notset”值

我使用类似的代码来填充属性,CSV文件只包含两个内容,用户LAN ID和属性值

填充字段不是问题,将值更改回“未设置”已被解决

这是我正在使用的代码

Import-module ActiveDirectory  
Import-CSV "code.csv" | % { 
$User = $_.cn 
$user.Put(“extensionAttribute15”, @())
$user.SetInfo()  
}
这里是错误

方法调用失败,因为[System.String]不包含名为“Put”的方法。 在attribute.ps1:4 char:10
+$user.Put读取CSV文件时,生成的对象只是简单的属性包。它们不支持任何特殊的方法,只支持平面数据。这些对象中没有任何内容不存在于CSV文件本身的文本中

如果要获取具有Active Directory上下文和功能的富对象,则需要从ActiveDirectory模块中的cmdlet获取一个富对象

像这样的东西可能正是你所需要的

Import-module ActiveDirectory  
Import-CSV "code.csv" | % { 
    $user = Get-ADUser $_.cn  # get a rich object from the AD module, by passing a string 
    $user.Put(“extensionAttribute15”, @())
    $user.SetInfo()  
}

您的问题是错误告诉您的是什么:您试图调用字符串中不存在的方法。首先将字符串转换为用户对象
$member=get-adGroupMember-identity$user