Using Splatting Hashtable for to set parameters and works well.
I am passing to a function as New-ADUser @param, the values that are set in splatting will be created in Active Directoy . However, my script will be running somewhere else. The Json file will be manipulated by the user.
How I can pass to this New-ADUser @param function the Json file instead Splatting table.
Thanks for your help.
Note: The following assumes that your JSON config file:
New-ADUserThese constraints ensure that a hashtable representation of that object can be used as-is for parameter splatting.
If you're running PowerShell (Core) 7+, you can take advantage of
ConvertFrom-Json's-AsHashtableparameter.In Windows PowerShell (whose latest and final version is 5.1), you have to manually convert the
[pscustomobject]instance returned byConvertFrom-Jsonto a hashtable:The sample config JSON you've provided in a comment indicates that the prerequisites stated at the top are not met, and that custom transformation of the config JSON is required in order to map onto the targeted
New-ADUserparameters:New-AzureADuser, for whose parameters the properties of the sample JSON below are a direct match, so no custom transformation is needed; hopefully, the technique shown is still useful to future readers who do need custom transformations.Note: I'm unsure as to what parameter the
mailNicknameproperty maps to; I've assumed-SamAccountNameabove; adjust as needed.