我想检查系统中是否已存在用户帐户.
$SamAc = Read-Host 'What is your username?'
$User = Get-ADUser -Filter {sAMAccountName -eq "$SamAc"}
Run Code Online (Sandbox Code Playgroud)
我不确定为什么,但$User即使{sAMAccountName -eq "$SamAc"}应该是真的,也总会返回null .
我在这里错过了什么?
编辑:
这是缺少的:
$User = Get-ADUser -Filter "sAMAccountName -eq '$SamAc'"
Run Code Online (Sandbox Code Playgroud)
编者按:该脚本块({ ... })用替换字符串.
我遇到了一个使用时未枚举特定属性的情况Get-ADUser -Properties *.例如,以下代码不会列出msDS-UserPasswordExpiryTimeComputed属性,即使它存在,我可以将其指定为-Properties参数,让它返回,并可以处理它的值.
# Does not return msDS-UserPasswordExpiryTimeComputed
Get-ADUser username -Properties *
# This works to get the msDS-UserPasswordExpiryTimeComputed attribute returned
Get-ADUser username -Properties msDS-UserPasswordExpiryTimeComputed
# If I really want all properties and this one
# I have to specify it alongside *
Get-ADUser username -Properties *, msDS-UserPasswordExpiryTimeComputed
Run Code Online (Sandbox Code Playgroud)
这不仅仅是从显示中省略属性的情况,我需要显式地声明msDS-UserPasswordExpiryTimeComputed属性,否则它只是在结果对象上不可用.
我已经知道Properties *在大多数情况下过滤并不是一个好主意,但我很好奇为什么所有 AD DS属性都没有被枚举,这正是我要求cmdlet做的事情.
这个问题是在询问,Get-ADUser但与Get-ADObjectcmdlet的大多数其他行为一样,我认为这种行为会延伸到大多数(如果不是全部)这些行为.
我创建了下面的脚本来查找自特定日期以来创建的所有 Unix 计算机。它不会返回错误,但也不起作用。脚本中仅使用一个日期,但两种格式具有相同的结果。
两种日期格式都不会失败,但它们不会返回任何内容——查询只是显示为正在运行,但从不返回任何数据:
$SomeDate1 = 'Wednesday, November 7, 2018 2:41:59 PM'
$SomeDate2 = '2018-11-07 14:41:59.000'
Get-ADComputer -Filter '*' -Properties * | Where {$($PSitem.CanonicalName) -like '*Unix*' -and $($PSitem.whenCreated) -gt $SomeDate1 } |`
Select Name,OperatingSystem,OperatingSystemVersion,ipv4Address,Created,whenCreated,Deleted,whenChanged,Modified,Description,@{Label="ServicePrincipalNames";Expression={$_.ServicePrincipalNames -join ";" }},DisplayName,Location,DistinguishedName,DNSHostName
Run Code Online (Sandbox Code Playgroud) 在使用简单脚本搜索代码设置静态IP地址后,我无法在StackOverflow上找到完整且易于实现的答案.这引出了以下问题:
什么是"简单的" - 实现代码将Windows 10 IP地址设置为静态IP地址,然后再返回动态IP地址?
^注意:Easy是一个指标,用于确保代码及其完整实现尽可能简单,而不是用户无法发现它具有挑战性.