#powershell Auto Type Conversion – String Array Concatenation

$a1 = “apple”
$a2 = “pear”, “guava”

# add/join 2 string arrays together
[array]$fruits = $a1 + $a2
# applepear guava
# $a1 is a simple string type;
# $a2 string array auto expanded and added to same string object

$fruits.count #1 unique string
$fruits.GetType() #a single unit of string array

# one correct way to add/join 2 string arrays together
# force conversion of $a1 simple string to a string array
$fruits = @($a1) + $a2

$fruits.count #3 items in array
$fruits.GetType() #an array of strings

# pear

#alternative if the order is not important
$fruits = $a2 + $a1

$fruits.GetType() #an array of 3 strings

#skype4b Audit Change Tracking Management?

With the right administrative permissions, a #skype4b administrator can add new or modify existing policies and global configuration settings. Every team member is happy when things go according to plan. If a system-wide or scope-level setting[1] goes awry, your end-users will likely be your most reliable “first level alarm” system. In this case, any remedial actions will visibly affect respective services or users in the firm.

Likewise, a Skype for Business enabled user… Continue reading

#powershell Get-Date v.s. [datetime] Format and System Locale

When a datetime attribute, say whenChanged in Active Directory gets dump to a text file via Export-Csv, the actual object type stored is that of a string. The format saved is dependent on the system locale. Typically for non en-us western locales, the day precedes the month instead of vice versa.

To convert this back to the proper datetime format through Import-Csv, use… Continue reading

#powershell Set-SmbShareAccess ?

Grant-SmbShareAccess is the go-to cmdlet to assign and modify permissions granted to trustees on a Windows NT file share as no Set-SmbShareAccess equipvalent exists.

*-SmbShareAccess and related cmdlets are available in PowerShell 4 and higher (Module: SmbShare) and are delivered only with operating systems Windows 8 and Windows Server 2012 (and later versions).

#powershell Grant-SmbShareAccess and Security Groups

Unlike net.exe share, Grant-SmbShareAccess can accept one or more security principals for both user accounts and groups (known as “trustee”) against the -AccountName parameter.

Hence instead of:

#requires -version 4.0
#Windows 8 and Windows Server 2012 or higher
Grant-SmbShareAccess `
-Name sharename`
-AccountName `
(Get-LocalGroupMember groupname).name `
-AccessRight Read -Verbose -Confirm:$false

, simply replace the value against -AccountName with groupname.

#powershell Get-Service StartType Property

Commencing with PowerShell v5, the startup type of a conventional Windows NT service is available as the StartType property with a call to the basic Get-Service cmdlet. Ironically, this property going by the name StartupType is already configuarable pre P5 using Set-Service (local administrative permissions needed).

In prior PS versions, a similar attribute StartMode can only be retrieved using Get-WmiObject plus the -Query or -Filter/-Property parameters:

gwmi -query “Select StartMode from Win32_Service Where Name=’wuauserv'”

gwmi -class Win32_Service -Property StartMode -Filter “Name=’wuauserv'”


&”$env:windir/system32/sc.exe” qc wuauserv | sls START_TYPE

gives the required value under START_TYPE.

#skype4b #powershell Get-CsWindowsService Missing Service

On a machine with the latest SkypeForBusiness Server 2015 PowerShell module, you successfully execute Get-CsWindowsService directly or remotely by wrapping the former in Invoke-Command with the -ComputerName parameter.

However, you noticed that targeting a Lync Server 2013 Front-End pool may omit some core services such as FabricHostSvc in the result set. This is despite the fact that you explicitly Import-Module Lync in the Invoke-Command statement.

The workaround is to check for the missing service and explicitly run Get-CsWindowsService -ComputerName $server -Name FabricHostSvc.

Note that although you can use Get-Service, the object type is that of ServiceController which differs from NTService returned from Get-CsWindowsService.

#powershell #skype4b Scheduled Task Does Not Work

You tested your #skype4b script from the PowerShell command line and are satisfied that everything works as expected. Next, you create a regular Windows scheduled task to run the script at a specific time of a day. However, you are surprised that no results are returned from simple cmdlets like Get-CsUser. You even wrap similar code in Invoke-Command and purposely target remote hosts with -ComputerName with no success.

Ultimately… Continue reading

#powershell Start-Job -ArgumentList Bug?

Irrespective of the position of -ArgumentList, including the intentional placement at the end of the statement per documentation for Start-Job, a string array will be treated as a single string object when passed to this cmdlet using the aforementioned parameter:

$arr = "a","b","c","d"
Start-Job -ScriptBlock {
param($a) $items = @(); $a | % { $items += $_; }; $items; } -ArgumentList $arr
$result = Receive-Job -id 2

Continue reading

#skype4b #powershell *-CsDatabase Common Error Messages (and Fix)

Even with the right administrative account and permissions, and proper network as well as firewall (port) settings provisioned, a number of common error messages when working with *-CsDatabase cmdlets in Skype for Business Server prove to be rather challenging to decipher and resolve:

PS C:\> Install-CsDatabase -SqlServerFqdn sql01.leedesmond.com -SqlInstanceName sql01inst01 -Update -ConfiguredDatabases
Install-CsDatabase : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ Install-CsDatabase -SqlServerFqdn sql01.leedesmond.com -SqlInstanceName sql01inst01 -Update -ConfiguredDatabases
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Install-CsDatabase], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.Rtc.Management.Deployment.InstallDatabaseCmdlet

Continue reading