문제

Hi i need to set the emailattribute to null/nothing on users. I have created this:

Get-ADGroupMember -Identity "testgrupp" | Get-ADUser -Properties samaccountname | Foreach {
Set-ADUser -Identity $_ -EmailAddress ("")
}

But it fails, i think its the last part that's wrong?

도움이 되었습니까?

해결책

Substitute ("") for $null:

Get-ADGroupMember -Identity "testgrupp" | 
Get-ADUser -Properties samaccountname | Foreach {
    Set-ADUser -Identity $_ -EmailAddress $null
}

다른 팁

A couple of ways to fix this:

Use the -ExpandProperty parameter of Select-Object so you only get the samaccountname strings:

Get-ADGroupMember -Identity "testgrupp" |
 Get-ADUser -Properties samaccountname | 
 Select -ExpandProperty samaccountname |
 Foreach {
          Set-ADUser -Identity $_ -EmailAddress ("")
        }

or reference the samaccountname property in your Set-ADUser:

Get-ADGroupMember -Identity "testgrupp" | 
Get-ADUser -Properties samaccountname | 
Foreach {
         Set-ADUser -Identity $_.samaccountname -EmailAddress ("")
        }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top