What does the CSV look like? Judging by the error message, you have at least few lines where the Target1ObjectId property is empty, you should remove those from the CSV or adjust the script logic to ignore them.
PowerShell Script giving error
I am using below PowerShell script to update manager attribute of guest users as their inviter.
Import-CSV C:\Users\Admin\AuditLog\AuditLogs_2022-10-14.csv | % { Set-AzureADUserManager -ObjectId $.Target1ObjectId -RefObjectId $.ActorObjectId }
Script is working and manager field is also getting updated but still its giving below error message.
Set-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:1 char:101
- ... csv | % { Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObj ...
- ~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Set-AzureADUserManager], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserManager
Set-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:1 char:101
- ... csv | % { Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObj ...
- ~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Set-AzureADUserManager], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserManager
Set-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:1 char:101
- ... csv | % { Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObj ...
- ~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Set-AzureADUserManager], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserManager
Set-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:1 char:101
- ... csv | % { Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObj ...
- ~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Set-AzureADUserManager], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserManager
Set-AzureADUserManager : Cannot bind argument to parameter 'ObjectId' because it is an empty string.
At line:1 char:101
- ... csv | % { Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObj ...
- ~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidData: (:) [Set-AzureADUserManager], ParameterBindingValidationException
- FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.Open.AzureAD16.PowerShell.SetUserManager
2 answers
Sort by: Oldest
-
-
Bruno Gomes 111 Reputation points
2022-10-16T07:11:33.08+00:00 It is not finding value in the variable, I don't know this method of putting the 'key' > 'dot' > 'column of the variable object' ($.Column). I always use $_ symbolizing that it is the object's row in the loop and then identifying the column like $_.Column
Other methods I use when an EmptyString error occurs in the variable is encapsulating the variable as:
$($._Column)
"$($._Column)"try like this:
Import-CSV C:\Users\Admin\AuditLog\AuditLogs_2022-10-14.csv | % {Set-AzureADUserManager -ObjectId $_.Target1ObjectId -RefObjectId $_.ActorObjectId}
or
Import-CSV C:\Users\Admin\AuditLog\AuditLogs_2022-10-14.csv | % {Set-AzureADUserManager -ObjectId "$($_.Target1ObjectId)" -RefObjectId "$($_.ActorObjectId)"}