Anyone here any good at refactoring scripts for this latest update?
We use an azure automation hybrid runbook worker that drops down onto one of our On Premise servers, and invokes commands. Below is our script. Would love some help here if anyone knows what to change.
[System.Management.Automation.PSCredential]$Credential1 = Get-AutomationPSCredential -Name 'Redacted'
$SecurePassword = $LogonSecret | ConvertTo-SecureString -AsPlainText -Force
$parameters = @{
ConfigurationName = 'Microsoft.Exchange'
ConnectionUri = 'http://redacted/PowerShell'
Credential = $Credential1
Authentication = 'Kerberos'
}
Invoke-Command @parameters -ScriptBlock {
New-RemoteMailbox -Name ($Using:FirstName + " " + $Using:LastName) -FirstName $Using:FirstName -LastName $Using:LastName -Password $Using:SecurePassword -UserPrincipalName $Using:LogonName -PrimarySMTP $Using:LogonName -OnPremisesOrganizationalUnit $Using:OU -Archive
Set-User -Identity $Using:LogonName -StreetAddress $Using:StreetAddress -City $Using:City -StateOrProvince $Using:State -PostalCode $Using:Zip -Office $Using:OfficeLocation -Phone $Using:PhoneNumber -Title $Using:Title -Department $Using:Department -Company $Using:Company -CountryOrRegion "United States"
Set-RemoteMailbox -Identity $Using:LogonName -EmailAddressPolicyEnabled $true
}