title: PowerShell - Cannot validate argument on parameter 'Identity'. The argument is null
body: <p>Hi I am new developing scripts in powershell and Active Directory, I am trying to run the following .ps1</p>
  <pre><code>#! /usr/bin/pwsh
  
  param ([String]$dns, [String]$adminUser, [String]$adminPassword, [String]$user, [String]$newPassword)
  
  $password = ConvertTo-SecureString -String $adminPassword -AsPlainText -Force
  $pass = ConvertTo-SecureString -String $newPassword -AsPlainText -Force
  $credential = New-Object System.Management.Automation.PSCredential ($adminUser, $password)
  $session = New-PSSession -cn $dns -Credential $credential -Authentication Negotiate
  Invoke-Command -Session $session -ScriptBlock {Set-ADAccountPassword -Identity $user -Reset -NewPassword ($pass)}
  </code></pre>
  <p>passing the arguments like this</p>
  <pre><code>./changePasswordAD.ps1 mydns myuser mypassword userToEdit NewPassword
  </code></pre>
  <p>the result obtained is the following</p>
  <pre><code>Set-ADAccountPassword: Cannot validate argument on parameter 'Identity'. The argument is null. Provide a valid value for the argument, and then try running the command again.
  </code></pre>
  <p>Why does this happen and how can I solve it?</p>
  <p>I am grateful in advance for your contributions</p>