My problem is that i don't know how to address my custom Attributes in AD Powershell
I normally user something like this
New-ADUser -Name "Test" -surname "User" -description "User Description"
However when i try to set a value to my custom attribute such as
New-ADUser -Name "Test" -surname "User" -description "User Description" -reportingManagerID "012345"
I receive this error:
New-ADUser : A parameter cannot be found that matches parameter name 'reportingManagerID'.
At line:1 char:247
+ ... " -StreetAddress "address" -Surname "User" -reportingManagerID "1234"
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.NewADUser
Any help would be much appreciated.
You need to use the -OtherAttributes parameter.
Quoting directly from the documentation here: https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-aduser?view=winserver2012-ps
To set the value of a custom attribute called favColors that takes a set of Unicode strings, use the following syntax:
-OtherAttributes #{'favColors'="pink","purple"}
To set values for favColors and dateOfBirth simultaneously, use the following syntax:
-OtherAttributes #{'favColors'="pink","purple"; 'dateOfBirth'=" 01/01/1960"}
Related
$user | ForEach {New-MsolUser -DisplayName $.Display name -FirstName $.First name -LastName $.Last name -UserprincipalName $.User principal name -LicenseAssignment $.Licenses -password WXAqa#123 -Office $.officeaddresss -MobilePhone $_.Phone number -UsageLocation "IN"}
it shows this kind of ERROR:
New-MsolUser : A positional parameter cannot be found that accepts argument 'name'.
At line:1 char:18
... | ForEach {New-MsolUser -DisplayName $.Display name -FirstName $.F ...
CategoryInfo : InvalidArgument: (:) [New-MsolUser], ParameterBindingException
FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Online.Administration.Automation.NewUser
I think the problem is that the variable names cannot include spaces. I am not sure about the dot at the start as well
Try using
$Display_name
Instead of
$.Display name
Similarly with all other variables of course.
New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes '#{'AttributeLDAPDisplayName'=value}'
I have tried using above command in powershell but returns following exception :
At line:1 char:45
+ New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes -Replace ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-ADGroup], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.ActiveDirectory.Management.Commands.NewADGroup```
As suggested by Santiago Squarzon posting it as
answer to help other community members.
If you use quotes in arguments, it will be treated as String. This is not valid for -OtherAttributes as the type of it is hashtable.
So, remove the quotes and include your values to the attribute by replacing value.
For suppose, if you are trying to create an Active Directory group based on Email address your cmdlet should be something like this:
$groupEmail = "user1#gmail.com","user2#gmail.com"
New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes #{'mail'=$groupEmail} -Path "CN=Users,OU=Your_OU_Name,DC=Com"
If you are trying to create AD group based on displayName, please check below cmdlet
(NOTE: You can also give the values directly like this):
New-ADGroup -Name 'mygroup1' -GroupScope 0 -OtherAttributes #{'displayName'="Sri","Devi"} -Path "CN=Users,OU=Your_OU_Name,DC=Com"
Make sure whether you are giving correct path or not.
Please check the below references if they are helpful.
References:
https://ss64.com/ps/new-adgroup.html
https://learn.microsoft.com/en-us/powershell/module/activedirectory/new-adgroup?view=windowsserver2022-ps#parameters
When I try to create a user policy for my active directory I get this error:
Invoke-Command : Cannot validate argument on parameter 'Session'. The argument is null or empty. Provide an argument that is
not null or empty, and then try the command again.
At C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\2.3.1\net472\SfBORemotePowershellModule.psm1:22959 char:38
+ ... -Session (Get-PSImplicitRemotingSession -CommandName 'New-CsApplic ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Invoke-Command], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeCommandCommand
The code that I'm using is this:
Import-Module MicrosoftTeams
# Get the credentials
$password = ConvertTo-SecureString -AsPlainText -Force -String "password"
$credentials = New-Object System.Management.Automation.PsCredential("email", $password)
# Connect to Microsoft Teams
Connect-MicrosoftTeams -Credential $credentials
New-CsApplicationAccessPolicy -Identity Random -AppIds "appid" -Description "Users"
Grant-CsApplicationAccessPolicy -PolicyName Random -Identity "userObjectId"
I know that the command New-CsApplicationAccessPolicy is creating the error but my guess is that it's caused by the command Connect-MicrosoftTeams because from what I can understand is that Connect-MicrosoftTeams creates a session.
Is there a way to set the session via a parameter or is this something you need to do outside this method?
I am trying to create a bulk of distribution lists, as instructed on technet site.
https://gallery.technet.microsoft.com/How-to-Bulk-create-6be6c82f#content
but i am encountering some errors while trying to work with the script they offered there.
This is my CSV
https://imgur.com/CXGoRIv
And this is the script of working with:
# Create Bulk Distribution Groupsmake CSV file
Import-Csv "C:\Users\user\Desktop\PowerShell\CreateDistributionLists.csv" | foreach {
New-DistributionGroup -Name $_.name -DisplayName $_.displayname –Alias $_.alias -PrimarySmtpAddress $_.PrimarySmtpAddress -RequireSenderAuthenticationEnabled ([boolean] $_.RequireSenderAuthenticationEnabled)}
when i launch the script, i get this error:
A positional parameter cannot be found that accepts argument '->RequireSenderAuthenticationEnabled'.
+ CategoryInfo : InvalidArgument: (:) [New-DistributionGroup], >ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New->DistributionGroup
+ PSComputerName : server.domain.com
Please Assist.
<<<< UPDATE >>
Edited script as suggested by Matias ( thanks buddy ).
Now i face the same error when launching.
A positional parameter cannot be found that accepts argument '->RequireSenderAuthenticationEnabled:'.
+ CategoryInfo : InvalidArgument: (:) [New-DistributionGroup], >ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New-DistributionGroup
in the csv , im typing "false" or "FALSE" under the "RequireSenderAuthenticationEnabled" column ,same as initially shown in the screenshot i attached.
To be RequireSenderAuthenticationEnabled to always be false...that will do the work for me, if you can help me edit the script to always be false in this, that will be awesome also, aslong as it work.
for reference, here is the script the way i use it now:
# Create Bulk Distribution Groupsmake CSV file
Import-Csv "C:\Users\user\Desktop\PowerShell\CreateDistributionLists.csv" | foreach {
New-DistributionGroup -Name $_.name -DisplayName $_.displayname –Alias $_.alias -PrimarySmtpAddress $_.PrimarySmtpAddress -RequireSenderAuthenticationEnabled:$([bool]::Parse($_.RequireSenderAuthenticationEnabled))}
<<< UPDATE SEP-03-2019 >>>
i have changed the script as suggested here to the following:
# Create Bulk Distribution Groupsmake CSV file
Import-Csv "C:\Users\user\Desktop\PowerShell\CreateDistributionLists.csv" | foreach {
New-DistributionGroup -Name $_.name -DisplayName $_.displayname –Alias $_.alias -RequireSenderAuthenticationEnabled $false}
Still i am getting the following error:
[PS] C:\users\user\Desktop\PowerShell>.\CreateDistributionLists.ps1
A positional parameter cannot be found that accepts argument '->RequireSenderAuthenticationEnabled'.
+ CategoryInfo : InvalidArgument: (:) [New-DistributionGroup], >ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New-DistributionGroup
+ PSComputerName : server.domain.com
Any suggestion ?
Thanks.
I'm having issues feeding variables into the New-MsolUser cmdlet. I'm getting the following error.
New-MsolUser : A positional parameter cannot be found that accepts argument 'â?UserPrincipalName ausertest#test.ie â?UsageLocation'.
At C:\users\test\Documents\test.ps1:148 char:1
+ New-MsolUser -DisplayName $TargetFullname â?"UserPrincipalName $TargetEmail â?" ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-MsolUser], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.Online.Administration.Automation.NewUser
The code I am using is:
$Source = "AnotherADUser"
$TargetFname = "New"
$TargetLname = "User"
$Target = "ausertest"
$TargetFullname = [string]::Concat($TargetFname ," ", $TargetLname)
$SourceEmail = (Get-ADUser $source -Property EmailAddress).EmailAddress
$SourceDomain = $SourceEmail.split("#")[1]
$TargetEmail = ([string]::Concat($Target , "#" , $SourceDomain))
New-MsolUser -DisplayName $TargetFullname –UserPrincipalName $TargetEmail –UsageLocation "IE" | Set-MsolUserLicense -AddLicenses "TESTINSTALL:EXCHANGESTANDARD"
This command works when I hardcode the details..
–UserPrincipalName and –UsageLocation use not the minus character but the
character with code 8211. Maybe it's fine but try to use the standard minus
instead, just to be sure.