PowerShell Send-MailMessage and Microsoft Exchange 2007 - email

I'm having a problem sending emails using Microsoft Exchange 2007.
I've used the exact same powershell code on a different machine and it sends the email.
The error message it gives is:
Send-MailMessage : Mailbox unavailable. The server response was: 5.7.1 Unable to relay
At C:\Users\alex\Desktop\Email.ps1:37 char:29
+ Send-MailMessage <<<< #Parameters
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpFailedRecipientException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
How would I fix this?

Your receive connector for relaying probably doesn't have the IP address of the computer you are running the script from. You need to check this on the Exchange server.

Related

VMware powercli connection error to single esxi homelab

Environment
Home VMware lab consisting of a single VMware ESXi host.
Client version: 1.33.4
Client build number: 14093553
ESXi version: 6.7.0
ESXi build number: 14320388
PC running the script
Windows 10
Powershell 5.1
VMware PowerCLI 12.0.0 build 15947286
user connecting has the vmware administrator role attached to it.
Code
clear-host
$vc = 'my-hhost-ip'
$user='myuser'
$pw='mypassword'
Set-PowerCLIConfiguration -InvalidCertificateAction:ignore
Connect-VIServer -server $vc -Protocol https -user $user -password $pw
Error
Connect-VIServer : Specified method is not supported.
At line:6 char:1
+ Connect-VIServer -server $vc -Protocol https -user $user -password $p ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotImplemented: (:) [Connect-VIServer], PSNotSupportedException
+ FullyQualifiedErrorId : NotSupported,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
PSMessageDetails :
Exception : System.Management.Automation.PSNotSupportedException: Specified method is not supported.
TargetObject :
CategoryInfo : NotImplemented: (:) [Connect-VIServer], PSNotSupportedException
FullyQualifiedErrorId : NotSupported,VMware.VimAutomation.ViCore.Cmdlets.Commands.ConnectVIServer
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 16
PipelineIterationInfo : {}
What I've tried
leaving of the credentials and having it ask, gives the same error
Deliberately getting the password wrong - gives an incorrect password message
Removing the administrator role from the user - gives a not authorised message
The output of the last two tests leads me to believe I am in fact authenticating ok, but that there is then some setting/service I've not set or enabled that allows it to connect after authenticating.
Any suggestions would be appreciated.
ESXi hosts assigned the free license don't grant access to consume the API services, which is what PowerCLI is doing under the covers.
The error message is confirming that you do not have the ability to access the API services.
Just to add a secondary answer in case anybody else stumbles upon it.
I thought at first that it was because I was connecting to my home eval edition.
However, I got the exact same issue when connecting to our corporate environment.
It turns out that my account on the machine was locked down to PowerShell constrained language mode. Running the commands on an account that did not have the mode set allowed them to run ok.
To add a further answer to this in case it helps anyone, in my case I just needed to run PowerShell as administrator.

How to connect a bot to Skype for business

I am currently working with the Microsoft Bot Framework and am trying to connect my bot to the new Skype for business channel.
I've followed the instructions:
Download and install the Skype for Business Online Connector module
Open Windows PowerShell as Administrator and run the following:
Import-PSSession (New-CsOnlineSession -Credential (Get-Credential))
Enter your Admin credentials
Run the following cmdlet:
New-CsOnlineApplicationEndpoint -ApplicationId botid -Name NameOfTheBot -Uri sip:username#yourdomain
I got our tenant admin to enter his credentials and also to create a domain account for the bot with an Office 365 licence. (I tried first to register bot without an Office 365 licence assigned).
When the bot account had an office 365 licence and tried to call the New-CsOnlineApplicationEndpoint I got the following error:
Cmdlet invocation error
+ CategoryInfo : NotSpecified: (:) [New-CsOnlineApplicationEndpoint], CmdletInvocationException
+ FullyQualifiedErrorId : Error processing cmdlet request,Microsoft.Rtc.Management.Hosted.PlatformService.NewPlatformServiceAppEndpointConfigCmdlet
+ PSComputerName : admin1e.online.lync.com
Could not find the application endpoint
+ CategoryInfo : InvalidOperation: (Microsoft.Rtc.M...cation endpoint:PlatformServiceCmdletException) [New-CsOnlineApplicationEndpoint], PlatformServiceException
+ FullyQualifiedErrorId : Could not get application endpoint or the Uri is already present as an User in BVD,Microsoft.Rtc.Management.Hosted.PlatformService.NewPlatformServiceAppEndpointConfigCmdlet
+ PSComputerName : admin1e.online.lync.com
Without the Office 365 licence I got the following error:
Cmdlet invocation error
+ CategoryInfo : NotSpecified: (:) [New-CsOnlineApplicationEndpoint], CmdletInvocationException
+ FullyQualifiedErrorId : Error processing cmdlet request,Microsoft.Rtc.Management.Hosted.PlatformService.NewPlatformServiceAppEndpointConfigCmdlet
+ PSComputerName : admin1e.online.lync.com
Exception of type 'Microsoft.Rtc.Management.Hosted.PlatformService.ProvisioningLibrary.ApplicationEndpointProvisioningException' was thrown.
+ CategoryInfo : InvalidOperation: (Microsoft.Rtc.M...on' was thrown.:PlatformServiceCmdletException) [New-CsOnlineApplicationEndpoint], ApplicationEndpointProvisioningException
+ FullyQualifiedErrorId : Exception of type 'Microsoft.Rtc.Management.Hosted.PlatformService.ProvisioningLibrary.ApplicationEndpointProvisioningException' was thrown.,Microsoft.Rtc.Management.Hosted.PlatformService.NewPlatformServiceAppEndpointConfigCmdlet
+ PSComputerName : admin1e.online.lync.com
I've also followed some of the more generic info around the Skype for Business connector as detailed here: https://msdn.microsoft.com/en-us/skype/trusted-application-api/docs/trustedapplicationendpoint
I've also tried to use a new account as mentioned in this issue but got the same error: Unable to connect bot to Skype For Business Online
You need to target the domain:
sip:botname#company.onmicrosoft.com
It appears it will not work if you target your custom domains.

Powershell PSSessionStateBroken error

I use the following powershell command to RDP to a server and start a service. It was working fine until last week before we cut over the server to a different data center.
Invoke-Command -ComputerName itbldw13 {Start-Service -Name bamboo-remote-agent}
The error that i get after the cut over is
Connecting to remote server itbldw13 failed with the following error message : The client cannot connect to the destination specified in the request.
+ CategoryInfo : OpenError: (itbldw13:String) [], PSRemotingTrans portException
+ FullyQualifiedErrorId : CannotConnect,PSSessionStateBroken
Could someone help me fix this error please

Powershell Remoting Failing After Server Restore

Our server had been set up to have Powershell Remoting enabled, so that we can remotely execute scripts from our developer machines. I should add that I am not massively fluent in Powershell and was not involved in setting this up.
However recently our server suffered a fault and subsequently had to be restored. The restoration process was supposed to restore Windows back to its last backed up state including all programs and data. However since the restore, Powershell Remoting no longer works on the server.
I receive the following error now when running Enter-PSSession ServerName.
Enter-PSSession : Connecting to remote server failed with the following error message : <f:WSManFault xmlns:f="http://s
chemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2147749890" Machine="ServerName"><f:Message></f:Message></f:WSManFaul
t> For more information, see the about_Remote_Troubleshooting Help topic.
At line:1 char:16
+ enter-pssession <<<< ServerName
+ CategoryInfo : InvalidArgument: (ServerName:String) [Enter-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : CreateRemoteRunspaceFailed
Or I get the following error when running New-PSSession ServerName
[ServerName] Connecting to remote server failed with the following error message : <f:WSManFault xmlns:f="http://schemas.
microsoft.com/wbem/wsman/1/wsmanfault" Code="2147749890" Machine="ServerName"><f:Message></f:Message></f:WSManFault> For
more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportExc
eption
+ FullyQualifiedErrorId : PSSessionOpenFailed
(I have replaced the actual server name above with ServerName for privacy purposes)
Any help is much appreciated
Based on this Microsoft Connect item, try adding-SessionOption (New-PSSessionOption -NoMachineProfile) to your Enter-PSSession command.
I have no idea why this would be needed, but it's worth a shot.

Remote Powershell Access denied for certain dll's execution for Sharepoint 2013

I am attempting to automate a sharepoint 2013 deployment via remote powershell from the build server. Everything executes as expected except when having anything to do with some class in sharepoint dll's such as (Microsoft.SharePoint.Publishing, Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings)
If I run the same script locally under the same credentials it runs fine.
I have considered the below:
The user has full admin right on both machines
Disabled UAC on the remote server
Followed the required Remote Powershell steps in thig post (http://social.technet.microsoft.com/Forums/sharepoint/en-US/09b60466-5432-48c9-aedd-1af343e957de/user-cannot-be-found-when-using-invokecommand-newspsite-on-sharepoint)
I set powershell to run as admin by defualt via the registry (New-Item -Path "Registry::HKEY_CLASSES_ROOT\Microsoft.PowershellScript.1\Shell\runas\command" -Force -Name '' -Value '"c:\windows\system32\windowspowershell\v1.0\powershell.exe" -noexit "%1"')
Script Code:
#Set the radio buttons value
$settings = New-Object Microsoft.SharePoint.Publishing.Navigation.WebNavigationSettings (,$rootWeb)
$settings.GlobalNavigation.Source = [Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
#Set the radio buttons value
$settings.CurrentNavigation.Source = [Microsoft.SharePoint.Publishing.Navigation.StandardNavigationSource]::PortalProvider
write-host "I am here.........................."
$settings.Update()
#Set the Publishing Web
$SPPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($rootWeb)
#Global Navigation Settings
$SPPubWeb.Navigation.InheritGlobal = $false
$SPPubWeb.Navigation.GlobalIncludePages = $false
The Remote Powershell output is as below:
I am here..........................
Exception calling "Update" with "0" argument(s): "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : UnauthorizedAccessException
+ PSComputerName : Contoso-DEVSP
Exception setting "GlobalIncludePages": "Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
+ CategoryInfo : NotSpecified: (:) [], SetValueInvocationException
+ FullyQualifiedErrorId : ExceptionWhenSetting
+ PSComputerName : Contoso-DEVSP
Many thanks in advance
You need to check CredSSP authentication. Remote PowerShell execution with SharePoint fails as the second hop translates the credentials to system credentials. If the task involves querying or updating DB server, it will fail as SYSTEM account will not have access the remote PowerShell on SQL Server. You need to enable CredSSP.
Check this blog post I wrote a while ago. This is not specific to SharePoint but it should apply to your scenario as well.
http://www.ravichaganti.com/blog/?p=1230