Ok, I got this working with WSMCredssp. I had to enable WSMancresssp on the server that the native commands would try and access:
Enable-WSManCredSSP -Role server -Force #run this on endpoint server
The last issue is how to add new line between the lines in the body of the email.
Thanks DON, great training, ready for feedback.
function Unlock-DOMUser {
[CmdletBinding()]
Param (
[parameter(Mandatory=$true,
Position=0,
ParameterSetName=“Status”)]
[parameter(Mandatory=$true,
Position=0,
ParameterSetName=“Unlock”)]
[parameter(Mandatory=$true,
Position=0,
ParameterSetName=“Reset”)]
[String]$DOMeid,
[parameter(Mandatory=$true,
ParameterSetName=“Status”)]
[Switch]$AccountStatus,
[parameter(Mandatory=$true,
ParameterSetName=“Unlock”)]
[Switch]$AccountUnlock,
[parameter(Mandatory=$true,
ParameterSetName=“Reset”)]
[Switch]$AccountReset,
[parameter(Position=2,
ParameterSetName=“Reset”)]
[String]$EmailAddress = “$DOMeid@domdom.com”
)
Begin{
#Get-Item -Path WSMan:\localhost\Client\TrustedHosts
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value 'atl01osi357' -Confirm:$false -Force
Enable-WSManCredSSP -DelegateComputer serv01oss333.DOM.DOM.com -Force -Role Client | Out-Null
$User = "DOM\svc-custkkreset"
$PWord = ConvertTo-SecureString –String 'password' -AsPlainText -Force
$Credential = New-Object –TypeName System.Management.Automation.PSCredential –ArgumentList $User, $PWord
$credsp1 = New-PSSession -ComputerName 'serv01oss333.DOM.DOM.com' -Credential $Credential -Name credssp1 -Authentication Credssp
}#end begin
Process{
if ( $AccountStatus ) {
Invoke-Command -session $credsp1 -ScriptBlock { param($DOMeid) net user $DOMeid /DOMAIN | FIND /I "Account active"} -ArgumentList $DOMeid
}#end if
if ( $AccountUnlock ) {
Invoke-Command -session $credsp1 -ScriptBlock { param($DOMeid) Net user $DOMeid /DOMAIN /active:YES } -ArgumentList $DOMeid
}#end if
if ( $AccountReset ) {
$randn = get-random -min 101 -max 999
[string]$randl = (Get-Random -InputObject 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' -Count 4)
$randl = $randl.Replace(' ','')
[string]$paswd = "!DOM"+$randl+$randn
Invoke-Command -session $credsp1 -ScriptBlock { param($DOMeid,$paswd) Net user $DOMeid $paswd /DOMAIN /active:YES } -ArgumentList $DOMeid,$paswd
Send-MailMessage -From "cs@domdom.com" `
-Cc me@DomDom.com `
-Subject "DOM Pasword Reset" `
-BodyAsHtml -Body "Your DOM password had been reset to $paswd, please reset at next logon. `
If you still need help, contact the Service Desk:`r`n `
For Field Associates: 777-llll For Corporate Campus: ext1111" `
-To "$EmailAddress" -SmtpServer email.DOM.com
}#end if
}#end process
End{
Remove-PSSession -Session $credsp1
Set-Item -Path WSMan:\localhost\Client\TrustedHosts -Value '' -Confirm:$false -Force
}#end end
}#end function