PowerShell Gallery Is Live!

More here: https://blogs.msdn.microsoft.com/powershell/2016/02/25/the-powershell-gallery-is-public/

Maybe try out:

Install-Module -Name RockPaperScissors

Advertisements

PowerShell – Calculated Property Example & Export-Csv Formatting


Import-Module MSOnline
Connect-MSOLService -Credential (Get-Credential)
$groupid = 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' # A GroupID with a known single Error.
$groupdetails = Get-MSOLGroup -ObjectID $groupid -ErrorAction 'Stop'
$groupdetails | `
Select-Object ObjectID,DisplayName,GroupType,`
@{ Label='ExpandedErrorCode';Expression={$PSItem.Errors[0].ErrorDetail.ObjectErrors.ErrorRecord.ErrorCode} },`
@{ Label='ExpandedErrorDescription';Expression={$PSItem.Errors[0].ErrorDetail.ObjectErrors.ErrorRecord.ErrorDescription} }
| `
Export-Csv -LiteralFile "$env:USERPROFILE\Desktop\MyGroupFile.csv" -NoTypeInformation
Remove-Variable groupid

Running $groupdetails | Get-Member shows Name of ‘Errors’ as a MemberType of: ‘Property’, with a Definition of: ‘System.Collections.Generic.List[Microsoft.Online.Administration.ValidationError] Errors {get;set;} ‘

PowerShell – Array vs. ArrayList Performance

Let’s take a look at performance when dealing with looping over an array variable; adding a new item and overall performance.
A standard array object in PowerShell is of a fixed size when created and cannot expand automatically. When you use the “+=” operator to append an entry, a new array object is created in memory with the additional overall previous array object. This leads to a large performance hit when dealing with a large number of items and increased memory consumption. For example:


$ArrayList = New-Object -TypeName 'System.Collections.ArrayList';
$Array = @();


Measure-Command
{
for($i = 0; $i -lt 10000; $i++)
{
$null = $ArrayList.Add("Adding item $i")
}
};
Measure-Command
{
for($i = 0; $i -lt 10000; $i++)
{
$Array += "Adding item $i"
}
};

Recommendation: use generics!

PowerShell – Single Quote vs. Double Quote

What’s the difference with quotes?

Single quote: It is taken literally and provided back.
Double quotes: PowerShell looks for the $ character inside of the double quotes. Once found, it assumes the following characters are the name of a variable up to the first space, is a variable name.

Sample:

[System.String]$a = 'Hello'
$b = '$a World!'
# $b prints: $a World!
$c = "$a World!"
# $c prints: Hello World!

Modifying Multivalued Attributes With PowerShell

[int] $ADS_PROPERTY_CLEAR = 1;
[int] $ADS_PROPERTY_UPDATE = 2;
[int] $ADS_PROPERTY_APPEND = 3;
[int] $ADS_PROPERTY_DELETE = 4;

# Get the user's Distinguished Name (DN) however you prefer.
# Utilize the above option switch to adjust.
$ADuser = [ADSI]"LDAP://SERVER-NAME-HERE/$($theUserAccount.DistinguishedName)"          
$ADuser.PutEx($ADS_PROPERTY_DELETE, "proxyAddresses", @("smtp:$userNameForUpdate@contoso.com"))
$ADuser.PutEx($ADS_PROPERTY_APPEND, "proxyAddresses", @("SMTP:$userNameForUpdate@extranet.contoso.com"))

# Commit the changes to the AD User Object:
$ADuser.SetInfo()

Reference:
http://technet.microsoft.com/en-us/library/ee156515.aspx

More Debian Adventures

Tried a NetBoot install of Debian and was a big fan of this post: http://www.octatech.net/blog/2014/08/things-to-do-after-installing-debian-8-jessie/

The NIC in my NUC wasn’t auto-detected initially and had to use a Debian Unstable net-boot image as mentioned in this post:
http://codepoets.co.uk/2014/installing-debian-jessie-on-an-intel-nuc-d54250wyk/