Module/Administration/Set-BCSUserPassword.ps1

<#
.SYNOPSIS
    Sets up a new Brightcom Tenant
.DESCRIPTION
     
.PARAMETER asda
 
.NOTES
    Author: Mathias Stjernfelt
    Website: http://www.brightcom.se
 
.EXAMPLE
    New-BCSTenant -CustomerName "Your Customer Name" -CreatePasswordStateEntry -PasswordStateUrl "https://passwordstate" -PasswordStateApiKey (Get-BCSSecureString "Your Private API Key")
 
    New-BCSTenant -CustomerName "Your Customer Name"
#>

function Set-BCSUserPassword {
  Param (
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
    $businessCentralServer = "sebcas01.brightcom.online",
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $false)]
    $businessCentralserverInstance = "BCNUP",
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    $CustomerName,
    [Parameter(ValueFromPipelineByPropertyName, Mandatory = $true)]
    [PSCredential]$BusinessCentralCredential
  )
  begin {}

  process {
    $moduleProfile = Get-BCSModuleProfile;

    $securePassword = ConvertTo-SecureString -String $moduleProfile.AzurePassword
    $credential = New-Object System.Management.Automation.PSCredential -argumentList $moduleProfile.AzureUserName, $securePassword

    Write-Host "Connection to server $businessCentralServer as user $($credential.UserName)"

    $vmSession = New-DeploymentRemoteSession -HostName $businessCentralServer -Credential $credential
    $sessionArgument = @{ "Session" = $vmSession }
    
    $tenant = $CustomerName.replace(' ', '')

    Invoke-Command @sessionArgument -ScriptBlock { 
      Param($serverInstance, 
            $tenant,
            [System.Management.Automation.PSCredential]$credential)
          
      $ErrorActionPreference = "Stop"
          
      Import-BCSDynamicsNavModules -serverInstance $serverInstance
      
      Write-Host "Updating $($credential.UserName) password."

      Set-NAVServerUser -ServerInstance $serverInstance -Tenant $tenant -UserName $credential.UserName -Password $credential.Password      
      
      Write-Host "Successfully Updated $($credential.UserName) password."

    } -ArgumentList $businessCentralserverInstance, $tenant, $BusinessCentralCredential
  }
  end {
  }
}

Export-ModuleMember -Function Set-BCSUserPassword