• Get-CsUser | Where-Object {$_.Enabled -eq "True"} • Get-CsUser | Where-Object {$_.Enabled -eq "True"} | Export-Csv MyCSV.CSV ref: http://technet.microsoft.com/en-us/library/ee176927.aspx#EIAA or get-help about_pipeline.

Download Report

Transcript • Get-CsUser | Where-Object {$_.Enabled -eq "True"} • Get-CsUser | Where-Object {$_.Enabled -eq "True"} | Export-Csv MyCSV.CSV ref: http://technet.microsoft.com/en-us/library/ee176927.aspx#EIAA or get-help about_pipeline.

• Get-CsUser | Where-Object {$_.Enabled -eq "True"}
• Get-CsUser | Where-Object {$_.Enabled -eq "True"} |
Export-Csv MyCSV.CSV
ref: http://technet.microsoft.com/en-us/library/ee176927.aspx#EIAA or get-help about_pipeline
• $usercredential= get-credential
• $lyncsession = new-pssession -connectionuri
https://<LyncFQDN>/ocspowershell -credential
$usercredential
Import-PSSession $lyncsession
• $LyncServer = “FE1.ocsguy.local”
• $Date = Get-Date
• $FileName = $(Read-Host -prompt “Enter file
name")
• $LastExitCode
• $Home –
• $_
• Get-Help About_Automatic_Variables
• $LyncServers = @(“Server1”,”Server2”,”Server3”)
• Invoke-expression c:\scripts\Test.ps1
• Invoke-command –filepath c:\scripts\Test.ps1 -
ComputerName Server1
• .\c:\Apps\MyEXE.exe
• .\MyEXE.exe 2>&1
• [string]$CommandOutput = .\CallFwdConfig.exe
$SIPAddress /Forward $Setting 2>&1
http://technet.microsoft.com/en-us/library/hh847842.aspx
• $Users = Get-CSUser | Where-Object {$_.Enabled –
eq $True}
• ForEach ($User in $Users)
{
write-host $User.SamAccountName “is enabled”
}
• $UserList = Import-CSV c:\scripts\users.csv
• $FileName = $(Read-Host -prompt “Enter file
name")
$UserList = Import-CSV $FileName
• $Users = Get-CSUser | Where-Object {$_.Enabled –
eq $false}
• ForEach ($User in $Users)
{
Set-CSUser –Identity $User.SamAccountName –
enabled $true
}
• $UserList.SamAccountName
• $UserList = Import-CSV c:\scripts\users.csv
• ForEach ($User in $UserList)
{
Enable-CSUser –Identity $User.SamAccountName
–SipAddress $User.SIPURI –RegistrarPool
FE1.ocsguy.local
}
• $FullE164Number = “tel:+”+$UserList.LineURI
• $UserList = Import-CSV c:\scripts\users.csv
• ForEach ($User in $UserList)
{
$FullE164Number = “tel:+”+$User.LineURI
Set-CSUser –Identity $User.SamAccountName –
LineURI $FullE164Number –EnterpriseVoiceEnabled
$true
}
• Start-Transcript Mylog.txt
• { Code Block Here }
• Stop-Transcript
*** Don’t forget to use –Verbose on all commands
within the script ***
• $OutputCSV = "CFCU_Bulk_Config" + (Get-Date -
Format s).Replace(":","-") +".csv"
• {"SIPAddress,Function,Setting,Result,ExitCode,Failure
Message,Delegates" | add-content .\$OutputCSV append}
if ($CommandOutput.Contains("was modified")){
write-host -ForegroundColor Green
$CFCUConfig.SIPAddress "is having forwarding setting
applied:" $CFCUConfig.Setting " ***** “
"$SIPAddress,Forward,$Setting,Success,$LASTEXITCOD
E" | Add-Content .\$OutputCSV
}
• $LastExitCode
• $Error
• $Error[0]
• $MaximumErrorCount
• $Error.Clear()
• Set-CSUser –identity Alan –LineURI 123 –
ErrorVariable $MyError
Write-EventLog -LogName "Lync Server" -Source "LS
Protocol Stack" -EntryType Information -EventId 65020
-Message “Your Message Text Here”
http://bit.ly/o5w0h2
• Edge server certificate stores are filling up on Lync
2010 Edges (Server 2008 R2)
• When this happens service availability is impacted
• Need a method to monitor this with SCOM
Note – this can be done from within Lync in 2013
$regkeycount = get-childitem -Path
'HKLM:\software\Microsoft\Cryptography\Services\Rtc
Srv\SystemCertificates\Accepted Certificates' | WhereObject -FilterScript {($_.Name -eq
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Crypt
ography\Services\RtcSrv\SystemCertificates\Accepted
Certificates\Certificates")}
$EventMessage = "There are "
+$regkeycount.SubKeyCount+ " certificates in the
Accepted Store.”
Blue font represents text, red represents variables
if ($regkeycount.SubKeyCount -lt 299)
{ Write Informational Message }
Else if ($regkeycount.SubKeyCount -lt 399)
{ Write Warning Message }
Else
{ Write Error Message }
Replace blue text with script blocks containing actual Write-EventLog syntax from next 3
slides
if ($regkeycount.SubKeyCount -lt 299)
{
Write-EventLog -LogName "Lync Server" -Source "LS
Protocol Stack" -EntryType Information -EventId 65020
-Message $EventMessage
}
Assumes $EventMessage is error or information captured from command output
elseif ($regkeycount.SubKeyCount -lt 399)
{
Write-EventLog -LogName "Lync Server" -Source "LS
Protocol Stack" -EntryType Warning -EventId 65021 Message $EventMessage
}
Assumes $EventMessage is error or information captured from command output
Write-EventLog -LogName "Lync Server" -Source "LS
Protocol Stack" -EntryType Error -EventId 65022 Message $EventMessage
Assumes $EventMessage is error or information captured from command output
#Counts certificates in Accepted Certificates store and writes to event log
$regkeycount = get-childitem -Path 'HKLM:\software\Microsoft\Cryptography\Services\RtcSrv\SystemCertificates\Accepted Certificates' |
Where-Object -FilterScript {($_.Name -eq
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography\Services\RtcSrv\SystemCertificates\Accepted Certificates\Certificates")}
if ($regkeycount.SubKeyCount -lt 299)
{
$EventMessage = "There are " +$regkeycount.SubKeyCount+ " certificates in the Accepted Store. No action is needed."
Write-EventLog -LogName "Lync Server" -Source "LS Protocol Stack" -EntryType Information -EventId 65020 -Message $EventMessage
}
elseif ($regkeycount.SubKeyCount -lt 399)
{
$EventMessage = "There are " +$regkeycount.SubKeyCount+ " certificates in the Accepted Store. This number is high."
Write-EventLog -LogName "Lync Server" -Source "LS Protocol Stack" -EntryType Warning -EventId 65021 -Message $EventMessage
}
else
{
$EventMessage = "There are " +$regkeycount.SubKeyCount+ " certificates in the Accepted Store. Please clear the store."
Write-EventLog -LogName "Lync Server" -Source "LS Protocol Stack" -EntryType Error -EventId 65022 -Message $EventMessage
}
• Organization is moving to closed federation model
• Large number of requests are expected to add
partner domains
• Need automated method based on output from
SharePoint (coming in CSV)
#Get Path and FileName
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$ofd = New-Object System.Windows.Forms.OpenFileDialog
# $ofd.InitialDirectory = $(pwd).path
$ofd.InitialDirectory = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
#Replace the text in quotes with instructions for the user on what file to select
$ofd.title = "Select the CSV containing the list of federated peers"
$ofd.ShowHelp=$true
if($ofd.ShowDialog() -eq "OK") { $ofd.FileName }
$FileName = $ofd.FileName
$Feds = import-csv $FileName
$transcriptname = "AddNewFederationPartners_" +
(Get-Date -Format s).Replace(":","-") +".txt"
Start-Transcript $transcriptname
foreach ($F in $Feds)
{
new-csalloweddomain -domain $F.Domain ProxyFQDN $F.Gateway -comment $F.Comment verbose
}
stop-transcript
#Import-Module Lync
#Get Path and FileName
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$ofd = New-Object System.Windows.Forms.OpenFileDialog
# $ofd.InitialDirectory = $(pwd).path
$ofd.InitialDirectory = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)
#Replace the text in quotes with instructions for the user on what file to select
$ofd.title = "Select the CSV containing the list of federated peers"
$ofd.ShowHelp=$true
if($ofd.ShowDialog() -eq "OK") { $ofd.FileName }
$FileName = $ofd.FileName
$Feds = import-csv $ofd.FileName
$transcriptname = "AddNewFederationPartners_" + (Get-Date -Format s).Replace(":","-") +".txt"
Start-Transcript $transcriptname
foreach ($F in $Feds)
{
new-csalloweddomain -domain $F.Domain -ProxyFQDN $F.Gateway -comment $F.Comment -verbose
}
stop-transcript
http://channel9.msdn.com/Events/TechEd
www.microsoft.com/learning
http://microsoft.com/technet
http://microsoft.com/msdn