powershell-3.0 - Powershell 中的 Get-ADComputer 失败并出现“参数上的标识属性为空或为空”错误
问题描述
我有一个用于调用的 powershell 脚本,Get-ADComputer
此时我收到此错误:
Get-ADComputer:无法验证参数“身份”上的参数。参数的 Identity 属性为 null 或空。
这是脚本:
$computers = Get-Content -Path C:\Users\computersforscript.txt
foreach($line in $computers)
{
Get-ADComputer -Identity $line -Properties * | FT Name, LastLogonDate, MemberOf -Autosize
}
$computers |
Select-Object Name,LastLogonDate,MemberOf |
Export-CSV -Path C:\Users\output.txt -NoTypeInformation
The script does iterate through each workstation on "computersforscript.txt
" but it does not export it and it errors out.
如果您能帮我解决这个问题,我将不胜感激。
解决方案
文件中似乎有空行。
您可以检查NullOrEmpty
和修剪空白。
foreach($line in $computers){
if(-not [String]::IsNullOrEmpty($Line)){
Get-ADComputer -Identity $line.Trim() -Properties * | FT Name, LastLogonDate, MemberOf -Autosize
}
}
推荐阅读
- python - 将查询参数添加到 URL
- python - 递增增加列表中的非零元素
- python - 使用 PIL 使文本大小自动调整为图像
- sql-server - SQL Server:不同表中列之间的关系
- javascript - 多次更改段落以匹配幻灯片中更改的图像
- php - magento 1.9.3.9 中损坏的模块块我如何调试问题
- machine-learning - 如何纠正来自外部环境的传感器漂移?
- meteor - meteor.js 和 React - 用于 SEO 的服务器渲染是否开箱即用?
- php - 作曲家不生成我制作的自动加载文件包
- java - 迁移到 Java 8 日期时间