2017-05-25 60 views
0

有沒有人曾經在PowerShell中做過這樣的事情?我正在自動創建新用戶,並且必須爲企業帳戶設置Skype。這是我到目前爲止有:在PowerShell中獲取Skype for Business的未分配電話號碼

<# set up skype for business #> 
Enable-CsUser -Identity $FULLNAME ` 
-RegistrarPool REDACTED 
-SipAddress $SIP 
Set-CsUser $FULLNAME ` 
-EnterpriseVoiceEnabled $true ` 
-ExchangeArchivingPolicy Uninitialized ` 
-LineURI $PHONENUMBER 
# only for driver manager/managers 
Grant-CsConferencingPolicy $FULLNAME ` 
-PolicyName $ConferencingPolicy 
Grant-CsExternalAccessPolicy -identity $FULLNAME ` 
-PolicyName 'Allow external access' 

所有我已經離開是分配的LineURI,我似乎無法找到如何做的事情。不過,我確實找到了script這樣做,但它似乎並不是特定於我的需求。我的問題是:如何在PowerShell中查詢Skype for Business以獲取第一個未分配號碼並將其分配爲LineURI?我一直在使用New-CSUnassignedNumber,但似乎無法取得任何進展。

+0

那麼你的問題是什麼? –

+0

@Bill_Stewart我不能相信我忘了把它寫進去。用這個問題編輯。 – Matt

回答

0

SFB不保留記錄你的號碼範圍,所以它不知道,如果你分配1299是最後的範圍內,或範圍延伸到1300年

Get-CsUser | ? LineUri | Select LineUri | Sort 

這將爲您提供組織中所有分配的uri的排序列表,因此您可以選擇可分配的uri,無論您可以使用多種方法來查找您要查找的內容,但您可能會對此感興趣在這個長期的方法中,它是一個腳本,它接受你的號碼範圍,並在一個不錯的Csv中輸出已用和可用的列表。

#region Input 
$NumRangeKeyTable = @{ 
    #Make sure numbers are in the same format as they are in Skype, 
    #Do not include any ';ext' or 'tel:' etc. formatting! 
    #Put single numbers in the format: 
    # "+35313456789" = "" 
    #Put number ranges in the format: 
    # "+35313456700" = "+35313456799" 

    "+35313456789" = "" 
    "+35313456700" = "+35313456799" 
} 

#Save Location, set to $null to be prompted for location. 
$FileName = $null 
#endregion 

#region Code 
#region Helper Functions 
Function Get-CsAssignedURIs { 
$AllNumbers = @() 
$Users = Get-CsUser 
$Users | ? {$_.LineURI -ne ""} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.LineURI ; Type = "User" }} 
$Users | ? {$_.PrivateLine -ne ""} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.PrivateLine ; Type = "PrivateLine" }} 
Get-CsRgsWorkflow | Where-Object {$_.LineURI -ne ""} | Select Name,LineURI | %{$AllNumbers += New-Object PSObject -Property @{Name = $_.Name ; SipAddress = $_.PrimaryUri ; Number = $_.LineURI ; Type = "Workflow" }} 
Get-CsCommonAreaPhone -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.LineURI ; Type = "CommonArea" }} 
Get-CsAnalogDevice -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.LineURI ; Type = "AnalogDevice" }} 
Get-CsExUmContact -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.LineURI ; Type = "ExUmContact" }} 
Get-CsDialInConferencingAccessNumber -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.PrimaryUri ; Number = $_.LineURI ; Type = "DialInAccess" }} 
Get-CsTrustedApplicationEndpoint -Filter {LineURI -ne $null} | %{ $AllNumbers += New-Object PSObject -Property @{Name = $_.DisplayName ; SipAddress = $_.SipAddress ; Number = $_.LineURI ; Type = "ApplicationEndpoint" }} 
Return $AllNumbers 
} 

function Get-UniqueExt { 
    Param(
     [string]$Uri1, 
     [string]$Uri2 
    ) 

    $Reg = "^([0-9+])+$" 

    if ([string]::IsNullOrEmpty($uri1) -and [string]::IsNullOrEmpty($Uri2)) { return "Two blank strings provided" } 
    if ($Uri1 -eq $Uri2) { return $Uri1 } 
    if ([string]::IsNullOrEmpty($uri1)) { return $Uri2 } 
    if ([string]::IsNullOrEmpty($uri2)) { return $Uri1 } 
    if ($Uri1.Length -ne $Uri2.Length) { return "Strings cannot be different lengths" } 
    if (($Uri1 -notmatch $Reg) -or ($Uri2 -notmatch $Reg)) { return "Strings must be in the format '0123..' or '+123..'" } 

    ($Uri1.Length-1)..0 | % { 
     if ($Uri1[$_] -ne $Uri2[$_]) { $Diff = $_ } 
    } 

    $Start = $Uri1.Substring(0,$Diff) 
    $Sub1 = $Uri2.Substring($Diff) 
    $Sub2 = $Uri1.Substring($Diff) 

    if ($Sub1 -lt $Sub2) { 
     $Min = $Sub1 ; $Max = $Sub2 
    } else { 
     $Min = $Sub2 ; $Max = $Sub1 
    } 

    $FormatStr = "" ; 1..$Min.Length | % { $FormatStr += "0"} 
    $Min..$Max | % { "$($Start)$($_.ToString($FormatStr))" } 
} 

function Save-ToFile { 
    Param(
    [Parameter(ValueFromPipeline=$True)] 
    $Item = $null, 
    [switch]$ReturnName, 
    $ExtFilter = "*", 
    $WinTitle = "Select File", 
    $FileTypeDisplay = $null 
    ) 

    If ($FileTypeDisplay -eq $null) { 
    If ($ExtFilter -eq "*") { 
     $ExtName = "All" 
    } Else { 
     $ExtName = (Get-Culture).TextInfo.ToTitleCase($ExtFilter) 
    }} Else { 
     $ExtName = (Get-Culture).TextInfo.ToTitleCase($FileTypeDisplay) } 

    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null 
    $FolderDialog = New-Object System.Windows.Forms.SaveFileDialog 
    $FolderDialog.Filter = "$($ExtName) files (*.$($ExtFilter.ToLowerInvariant()))| *.$($ExtFilter.ToLowerInvariant())" 
    $FolderDialog.Title = $WinTitle 
    $Result = $FolderDialog.ShowDialog() 

    If ($Result -eq "OK"){ 
    $Item | Out-File $FolderDialog.FileName -Append 
    If ($ReturnName) { return $FolderDialog.FileName }} 
    Else { 
    Write-Error "No file selected" } 
} 
#endregion 

Function Main { 
Param ([Hashtable]$NumRanges) 

#region Process Data 
$AllNums = $NumRanges.Keys | % { 
    Get-UniqueExt -Uri1 $_ -Uri2 $NumRanges[$_] 
} 
$S4BNums = Get-CsAssignedURIs 
$S4BNums | % { $_.Number = ($_.Number.Split(';')[0] -ireplace "tel:","") } 

$KT = @{} 

$S4BNums | % { 
    $KT[$_.Number] = $_ 
} 

$FullRecord = $AllNums | Sort | % { 
    $Number = $_ 
    $Type = "" 
    $Name = "" 

    if ($KT[$_] -ne $null){ 
     $UseDetails = $KT[$_] 
     $Name = $UseDetails.Name 
     $Type = $UseDetails.Type 
    } 

    [PSCustomObject]@{ 
     Number = $Number 
     Name = $Name 
     Type = $Type 
    } 
} 
#endregion 

return $FullRecord 
} 

$Results = Main $NumRangeKeyTable 

#region Output-Data 
    if ($FileName -eq $null) { 
    $FileName = (Save-ToFile -Item "" -ReturnName -ExtFilter "Csv") 
    } 
    if ($FileName -ne $null) { 
    $Results | Export-Csv -Path $FileName -NoTypeInformation 
    } else { $Results | Out-GridView } 
#endregion 
#endregion 
+0

太棒了。感謝你的回答。 – Matt

+0

@Matt不用擔心,我對自己的SfB環境基本上碰到了同樣的問題,並希望能在客戶網站上重複使用。 – ConnorLSW