PowerShell Script giving error

ravi ranjan 1 Reputation point
2022-10-15T18:41:34.653+00:00

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
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,664 questions
{count} votes

2 answers

Sort by: Most helpful
  1. 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)"}  
    
    1 person found this answer helpful.

  2. Vasil Michev 95,836 Reputation points MVP
    2022-10-16T05:55:30.983+00:00

    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.

    0 comments No comments