I want to configure the Outlook profile with the email account and I'm taking the values from the stored credentials. But when I run the script, it shows
Start-Process : This command cannot be run due to the error: The filename or extension is too long.
The code is as follows:
clear
if($process=(get-process 'outlook' -ErrorAction SilentlyContinue))
{
Write-Host "Outlook is running so close it.." -ForegroundColor Green
kill($process)
Write-Host "Outlook is stopped " -ForegroundColor Green
}
$reg="HKCU:\Software\Microsoft\Office\16.0\Outlook\Profiles"
Write-Host "create new profile for outlook" -ForegroundColor Green
"`n"
New-Item -Name "outlook" -Path $reg -Force -Verbose
Write-Host "New profile created" -ForegroundColor Green
"`n"
Write-Host "Launch outlook with newly created profile" -ForegroundColor Green
$Login = Get-StoredCredential -Target 'test'
$Decrypt = $Login.Password | ConvertFrom-SecureString
$Encrypt = $Decrypt | ConvertTo-SecureString -AsPlainText -Force
$passwd=[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($Encrypt))
$Password = ConvertTo-SecureString $passwd -AsPlainText -Force
$cred = new-object -Typename System.Management.Automation.pscredential -ArgumentList($Login.UserName, $password)
Start-Sleep -s 5
Start-Process 'OUTLOOK.EXE' -Credential $cred -ArgumentList '/profile "outlook" '
Error:
Start-Process : This command cannot be run due to the error: The filename or extension is too long.
At line:1 char:2
+ Start-Process 'OUTLOOK.EXE' -Credential $cred
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessComm
and
In this script, I'm able to create a new profile but unable to launch the outlook with newly created profile including the email account part.