Although the PowerShell portion has not been thoroughly tested, based on your data, this should provide the right PowerShell commands. If it is the correct PowerShell script, uncomment several lines. I deleted the private URL for the business.
It would be better to utilize #users instead of concatenating the PowerShell commands for each user into a single remote PowerShell session.
Option Explicit
Sub createskype2()
Dim pid As Variant
Dim command1 As String
Dim command2 As String
Dim command3 As String
Dim exitcmd As String
Dim username As String
Dim exe0 As String
Dim exe1a As String, exe2a As String
Dim sleep As String
Dim call0 As String
Dim call1 As String
Dim call2 As String
Dim call3 As String
Dim call4 As String
Dim call5 As String
Dim call6 As String
Dim call7 As String
Dim i As Long
sleep = "Start-Sleep -s 60"
' command = "Enable-CsUser "
' command0 = " -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:"
' command1 = "@abc.com'"
' command2 = "Set-CsUser "
' command3 = " -AudioVideoDisabled $True"
' command4 = "@abcdsss.com'"
command1 = "Enable-CsUser <USER> -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:<USER>@abc.com'"
command2 = "Enable-CsUser <USER> -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:<USER>@abcdsss.com'"
command3 = "Set-CsUser <USER> -AudioVideoDisabled $True"
exitcmd = "Remove-PSSession -Session (Get-PSSession)"
call0 = "powershell -noprofile -command ""&{"
call1 = "$username = 'xxxxxx'"
call2 = "$password = '12345678'"
call3 = "$secstr = New-Object -TypeName System.Security.SecureString"
call4 = "$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)}"
call5 = "$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr"
call6 = "$session = New-PSSession -ConnectionUri https://MyServer/OcsPowershell -Credential $cred"
call7 = "Import-PSSession -Session $session}"""
' exe1 = call0 & ";" & call1 & ";" & call2 & ";" & call3 & ";" & call4 & ";" & call5 & ";" & call6 & ";" & call7 & ";"
exe0 = Join(Array(call0, call1, call2, call3, call4, call5, call6, call7), ";") & ";"
Debug.Print "exe0:", exe0
With ThisWorkbook.Worksheets("Create Email Account")
For i = 8 To .Cells(Rows.Count, "B").End(xlUp).Row
If Not IsEmpty(.Cells(i, "B")) Then
username = .Cells(i, "B").Value
exe1a = Replace(command1, "<USER>", username) & ";" & sleep & ";" & Replace(command3, "<USER>", username) & ";" & exitcmd
exe2a = Replace(command2, "<USER>", username) & ";" & sleep & ";" & Replace(command3, "<USER>", username) & ";" & exitcmd
' exe1a = command & " " & username & " " & command0 & username & command1 & ";" & sleep & ";" & command2 & " " & username & " " & command3
' exe2a = command & " " & username & " " & command0 & username & command4 & ";" & sleep & ";" & command2 & " " & username & " " & command3
If LCase(.Cells(i, "A")) = "a" Then
Debug.Print exe0 & exe1a
' pid = Shell(exe0 & exe1a, vbNormalFocus)
' .Cells(i, "H").Interior.Color = XlRgbColor.rgbGreen
Else
Debug.Print exe0 & exe2a
' pid = Shell(exe0 & exe2a, vbNormalFocus)
' .Cells(i, "H").Interior.Color = XlRgbColor.rgbGreen
End If
End If
' Application.Wait Now + TimeSerial(0, 0, 10)
Next i
End With
MsgBox "Skype account(s) has/have been created."
End Sub
Immediate Window Output:
exe0: powershell -noprofile -command "&{;$username = 'xxxxxx';$password = '12345678';$secstr = New-Object -TypeName System.Security.SecureString;$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)};$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;$session = New-PSSession -ConnectionUri https://MyServer/OcsPowershell -Credential $cred;Import-PSSession -Session $session}";
powershell -noprofile -command "&{;$username = 'xxxxxx';$password = '12345678';$secstr = New-Object -TypeName System.Security.SecureString;$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)};$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;$session = New-PSSession -ConnectionUri https://MyServer/OcsPowershell -Credential $cred;Import-PSSession -Session $session}";Enable-CsUser KKLM -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:KKLM@abc.com';Start-Sleep -s 60;Set-CsUser KKLM -AudioVideoDisabled $True;Remove-PSSession -Session (Get-PSSession)
powershell -noprofile -command "&{;$username = 'xxxxxx';$password = '12345678';$secstr = New-Object -TypeName System.Security.SecureString;$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)};$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;$session = New-PSSession -ConnectionUri https://MyServer/OcsPowershell -Credential $cred;Import-PSSession -Session $session}";Enable-CsUser KSTG -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:KSTG@abc.com';Start-Sleep -s 60;Set-CsUser KSTG -AudioVideoDisabled $True;Remove-PSSession -Session (Get-PSSession)
powershell -noprofile -command "&{;$username = 'xxxxxx';$password = '12345678';$secstr = New-Object -TypeName System.Security.SecureString;$password.ToCharArray() | ForEach-Object {$secstr.AppendChar($_)};$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $secstr;$session = New-PSSession -ConnectionUri https://MyServer/OcsPowershell -Credential $cred;Import-PSSession -Session $session}";Enable-CsUser PCLU -RegistrarPool 'LyncPrimaryFrontPool.abc.com' -SipAddress 'sip:PCLU@abc.com';Start-Sleep -s 60;Set-CsUser PCLU -AudioVideoDisabled $True;Remove-PSSession -Session (Get-PSSession)