2017-05-25 3 views
0

誰もこれをpowershellでこれまでしたことがありますか?私は新しいユーザー作成を自動化し、ビジネスアカウント用にSkypeをセットアップしなければなりません。ここで私がこれまで持っているものです。Skype for Business for powershellの割り当てられていない電話番号を取得する

<# 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を使用していますが、進歩を遂げることはできません。範囲は1300年の

Get-CsUser | ? LineUri | Select LineUri | Sort 

この意志に広がっている場合、あなたの番号範囲の

+0

あなたの質問は何ですか? –

+0

@Bill_Stewartそれを入れるのを忘れたとは信じられません。 – Matt

答えて

0

SFBは、記録を保持していないので、範囲内の最後であるあなたが1299を割り当てるかどうかは分かっていない、またはあなたの組織内のすべての割り当てられた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

関連する問題