Latest

Export-SessionCommand function to export PS script commands to remote PS session


Have you been in the situation where you’re in a PS session trying to run commands against one or more remote computers using PowerShell Remoting sessions? You may have PS modules and cmdlets in the current PS session that are not available in the remote session(s). This function will allow you to export local PS session commands to remote PS sessions. The native Export-PSSession cmdlet seems to do the opposite – bringing remote session cmdlets to local PS session.

Export-SessionCommand PowerShell function is part of the SB-Tools PowerShell module. This function takes one or more Powershell script functions/commands from current session and exports them to a remote PS session. This function will ignore and not export binary functions.  Exported functions will persist on the remote computer for the user profile used with the PS remote session.

The function takes the following parameters:

Command

This is a required parameter. This is one or more script commands available in the current PS session. For example Update-SmbMultichannelConnection cmdlet/function of the SmbShare PS module.
To see available script commands, you can use:

Get-Command | ? { $_.CommandType -eq 'function' }

ModuleName

This is an optional parameter that defaults to ‘SBjr’ if not provided. This is the name of the module that this function will create on the remote computer under the user profile of the remote PS session. This will over-write prior existing module with the same name.

Session

System.Management.Automation.Runspaces.PSSession object usually obtained by using New-PSSession cmdlet

Example

$Session = New-PSSession -ComputerName 'Mycomp.MyDomain.com' -Credential (Get-SBCredential -UserName 'domain\user')

Export-SessionCommand get-saervice,get-sbdisk,bla,get-bitlockerstatus,get-service -Session $Session -Verbose


To use the SB-Tools PowerShell module which is available in the PowerShell Gallery, you need PowerShell 5. To view your PowerShell version, in an elevated PowerShell ISE window type

$PSVersionTable

To download and install the latest version of SB-Tools from the PowerShell Gallery, type

Install-Module SB-Tools,POSH-SSH -Force

SB-Tools contains functions that depend on POSH-SSH module, and they’re typically installed together.

To load the SB-Tools and POSH-SSH modules type:

Import-Module SB-Tools,POSH-SSH -DisableNameChecking

To view a list of cmdlets/functions in SB-Tools, type

Get-Command -Module SB-Tools

To view the built-in help of one of the SB-Tools functions/cmdlets, type

help <function/cmdlet name> -show

such as

help Convert-IpAddressToMaskLength -show

Advertisements

Get-SBWMI function to query WMI with Timeout option


29 September 2017 update:

I’ve added an additional parameter to allow passing a PSCredential object to this function/cmdlet. This is helpful when the user running the script/cmdlet does not have permissions on the target computer. Another enhancement in this update to to trap errors resulting from failure to WMI connect to the target computer like in case of ‘Access Denied’, or ‘RPC Server not available’ errors.


Get-SBWMI PowerShell function is part of the SB-Tools PowerShell module. It provides similar functionality to the native Get-WMIObject cmdlet with added option: Timeout.

The function takes 1 required parameter; ‘Class’. For example

Get-SBWMI Win32_computerSystem

will return output similar to:

It also accepts the following optional parameters:

Property

Property name of the provided ‘Class’ such as ‘NumberofLogicalProcessors’ property of the ‘Win32_computerSystem’ class:

Get-SBWMI Win32_computerSystem -Property NumberofLogicalProcessors

Filter

In the format Property=Value such as ‘DriveLetter=e:’

Get-SBWMI -Class Win32_Volume -Filter 'DriveLetter=e:'

ComputerName

Remote computer name or IP address

Get-SBWMI Win32_computersystem -ComputerName mgmt

NameSpace

The default is ‘root\cimv2’. To see name spaces type:

(Get-WmiObject -Namespace 'root' -Class '__Namespace').Name

TimeOut

In seconds. The default is 20.

This is a particularly helpful option especially if you’re in the situation of trying to query many hundreds or thousands of computers, where the vast majority respond quickly but few can drag out for several minutes or not respond at all causing the script to hang if using the native Get-WMIObject cmdlet.


To use the SB-Tools PowerShell module which is available in the PowerShell Gallery, you need PowerShell 5. To view your PowerShell version, in an elevated PowerShell ISE window type

$PSVersionTable

To download and install the latest version of SB-Tools from the PowerShell Gallery, type

Install-Module SB-Tools,POSH-SSH -Force

SB-Tools contains functions that depend on POSH-SSH module, and they’re typically installed together.

To load the SB-Tools and POSH-SSH modules type:

Import-Module SB-Tools,POSH-SSH -DisableNameChecking

To view a list of cmdlets/functions in SB-Tools, type

Get-Command -Module SB-Tools

To view the built-in help of one of the SB-Tools functions/cmdlets, type

help <function/cmdlet name> -show

such as

help Convert-IpAddressToMaskLength -show

Convert-IpAddressToMaskLength and Convert-MaskLengthToIpAddress PowerShell functions


Convert-IpAddressToMaskLength and Convert-MaskLengthToIpAddress PowerShell functions are two supporting functions in the SB-Tools PowerShell module that do what their names suggest.

These two functions come in handy when manipulating IPv4 addresses. For example, when adding/removing IPv4 address to/from a network interface using PowerShell during automated provisioning.

For example, the Get-NetIPAddress cmdlet of the NetTCPIP module, returns information similar to

Notice that the familiar dotted decimal subnet mask is missing. Instead we get ‘PrefixLength’ which is the number of bits that represent the network address out of the 32 bit IPv4 address. So, a 24 bit prefix means a 255.255.255.0 subnet mask.

The Convert-IpAddressToMaskLength function takes one or more dotted decimal subnet masks and returns the corresponding bit lengths. For example

Convert-IpAddressToMaskLength 255.0.0.0,255.192.0.0,255.255.255.224

will return 8,10,27

Similarly, the Convert-MaskLengthToIpAddress 9,11,28 will return:


To use the SB-Tools PowerShell module which is available in the PowerShell Gallery, you need PowerShell 5. To view your PowerShell version, in an elevated PowerShell ISE window type

$PSVersionTable

To download and install the latest version of SB-Tools from the PowerShell Gallery, type

Install-Module SB-Tools,POSH-SSH -Force

SB-Tools contains functions that depend on POSH-SSH module, and they’re typically installed together.

To load the SB-Tools and POSH-SSH modules type:

Import-Module SB-Tools,POSH-SSH -DisableNameChecking

To view a list of cmdlets/functions in SB-Tools, type

Get-Command -Module SB-Tools

To view the built-in help of one of the SB-Tools functions/cmdlets, type

help <function/cmdlet name> -show

such as

help Convert-IpAddressToMaskLength -show

PowerShell module with functions to Get AD FSMO roles, Get and Set NTP server setting


This module can be downloaded from the Microsoft Script Center Repository.

The module does not require ActiveDirectory PS module, and includes 3 functions:

Get-ADRole: This is a function to return one or all DC FSMO role holders in the current AD forest

Get-NTPDCs: This is a function to return NTP server settings for one or all DCs in current AD forest

Set-NTP: This is a function to change NTP server settings for one or more DCs in current AD forest

Example:

$DCNames = ((([DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()).Sites).Servers).Name
$DCNames -notmatch (Get-ADRole PdcRole).DCName | % { Set-NTP $_ time-c.nist.gov }

This example will change NTP server setting on all DCs except PDC emulator to ‘time-c.nist.gov’

Of course for this to work, it needs to to be run under an AD user that has permission to write to the DCs’ registry.

Getting started:

  • To use the functions/cmdlets in this module, download this module, extract the files using Winrar for example.
  • Open PowerShell ISE as Administrator
  • Open and execute the Install-Module.ps1 script

StorSimple 8k software release 4.0


Around mid February 2017, Microsoft released StorSimple software version 4.0 (17820). This is a release that includes firmware and driver updates that require using Maintenance mode and the serial console.

Using this PowerShell script to save the Version 4.0 cmdlets and compare them to Version 3.0, I got:

storsimple40-a

Trying the new cmdlets, the Get-HCSControllerReplacementStatus cmdlet returns a message like:

storsimple40-b

The Get-HCSRehydrationJob returns no output (no restore jobs are running)

The Invoke-HCSDisgnostics seems pretty useful and returns output similar to:

storsimple40-c

The cmdlet takes a little while to run. In this case it took 14 minutes and 38 seconds:

storsimple40-d

It returns data from its several sections like;

System Information section:

storsimple40-e

This is output similar to what we get from the Get-HCSSystem cmdlet for both controllers.

Update Availability section:

storsimple40-f

This is output similar to Get-HCSUpdateAvailability cmdlet, although the MaintenanceModeUpdatesTitle property is empty !!??

storsimple40-g

Cluster Information section:

storsimple40-h

This is new exposed information. I’m guessing this is the output of some Get-HCSCluster cmdlet, but this is pure speculation on my part. I’m also guessing that this is a list of clustered roles in a traditional Server 2012 R2 failover cluster.

Service Information section:

storsimple40-i

This is also new exposed information. Get-Service is not an exposed cmdlet.

Failed Hardware Components section:

storsimple40-j

This is new exposed information. This device is in good working order, so this list may be false warnings.

Firmware Information section:

storsimple40-k

This output is similar to what we get from Get-HCSFirmwareVersion cmdlet

Network Diagnostics section:

storsimple40-l

Most of this information is not new, but it’s nicely bundled into one section.

Performance Diagnostics section:

storsimple40-m

Finally, this section provides new information about read and write latency to the configured Azure Storage accounts.

The full list of exposed cmdlets in Version 4.0 is:

Clear-DnsClientCache
Set-CloudPlatform
Select-Object
Restart-HcsController
Resolve-DnsName
Out-String
Out-Default
Set-HcsBackupApplianceMode
Measure-Object
Invoke-HcsmServiceDataEncryptionKeyChange
Invoke-HcsDiagnostics
Get-History
Get-Help
Get-HcsWuaVersion
Get-HcsWebProxy
Invoke-HcsSetupWizard
Set-HcsDnsClientServerAddress
Set-HcsNetInterface
Set-HcsNtpClientServerAddress
Test-HcsNtp
Test-HcsmConnection
Test-Connection
Sync-HcsTime
Stop-HcsController
Start-Sleep
Start-HcsUpdate
Start-HcsPeerController
Start-HcsHotfix
Start-HcsFirmwareCheck
Set-HcsWebProxy
Set-HcsSystem
Set-HcsRemoteManagementCert
Set-HcsRehydrationJob
Set-HcsPassword
Get-HcsUpdateStatus
Trace-HcsRoute
Get-HcsUpdateAvailability
Get-HcsSupportAccess
Enable-HcsRemoteManagement
Enable-HcsPing
Enable-HcsNetInterface
Disable-HcsWebProxy
Disable-HcsSupportAccess
Disable-HcsRemoteManagement
Enable-HcsSupportAccess
Disable-HcsPing
Test-NetConnection
Test-HcsStorageAccountCredential
TabExpansion2
Reset-HcsFactoryDefault
prompt
Get-NetAdapter
Disable-HcsNetInterface
Enable-HcsWebProxy
Enter-HcsMaintenanceMode
Enter-HcsSupportSession
Get-HcsRoutingTable
Get-HcsRemoteManagementCert
Get-HcsRehydrationJob
Get-HcsNtpClientServerAddress
Get-HcsNetInterface
Get-HcsFirmwareVersion
Get-HcsDnsClientServerAddress
Get-HCSControllerReplacementStatus
Get-HcsBackupApplianceMode
Get-Credential
Get-Command
Export-HcsSupportPackage
Export-HcsDataContainerConfig
Exit-PSSession
Exit-HcsMaintenanceMode
Get-HcsSystem
Update-Help

Powershell script to get disk information including block size


This script can be downloaded from the Microsoft Technet Gallery. It contains the Get-SBDisk function which takes one parameter as input being one or more computer names or IP addresses. It return s a PowerShell object for each fixed disk of each input computer.

To see the inline help and example:

help Get-SBDisk -ShowWindow

get-sbdisk2

This script takes advantage of this function and collects disk information on all computers in the current AD domain (without the need to use ActiveDirectory PowerShell module):

$adsi = [adsisearcher]"objectcategory=computer"
$adsi.SearchRoot = "LDAP://dc=$($env:USERDNSDOMAIN.replace('.',',dc='))"
$adsi.filter = "(&(objectClass=Computer)(!userAccountControl:1.2.840.113556.1.4.803:=2))" # enabled computers
$adsi.PageSize = 1000000 
$EnabledADComputers = $adsi.FindAll()
$EnabledADComputerNames = @()
$EnabledADComputerNames += $EnabledADComputers | % { $_.Properties.name } # List of the names of enabled computers from AD
$i = 0
$DiskInfo = @()
$EnabledADComputerNames | % {
   $i++
   Write-Progress -Activity "Checking disks on computer $_" -Status "$i of $($EnabledADComputerNames.Count)"
   $DiskInfo += Get-SBDisk $_ -Verbose
}
$DiskInfo | FT -a # output disk information to console
$DiskInfo | Out-GridView # Output disk information to ISE grid view
$DiskInfo | Export-Csv .\DiskInfo.csv -NoType # Save disk information to CSV

"Checked $($EnabledADComputerNames.Count) computers in AD"
"Found $(($DiskInfo | % { $_.ComputerName } | select -Unique).Count) reachable computers"
"$($DiskInfo.Count) disks checked"

get-dbdisk3

This is formatted to work with PS version 2.

During the script run you may see progress similar to:

get-sbdisk1

and output similar to:

get-dbdisk4

To view a list of disks with less than 20% free space:

"Disks with less than 20% free space"
$DiskInfo | 
    where { $_.'Free(%)' -lt 20 -and $_.'Free(%)' -ne 100 } | 
       sort 'Free(%)' | FT -a

get-dbdisk5

 

 

PowerShell script to report on computer inventory


Back in October of 2014 I responded to a TechNet Script Center Repository Request

ping01

The script I wrote back then looked like:

ping02

Based on user feedback I decided to update this script. Version 2 is now online. Enhancements in version 2 include:

  • Powershell 2.0 compatibility (Windows 7 and Server 2008 native, Windows 2003 and Windows XP possible)
  • Script version 2 is backward compatible with script version 1 in the sense that example are provided to use script v2 to produce same output as script v1
  • Both scripts return output as a PS Object which lends itself handy to further automation
  • Added -Verbose output, removed ‘log’ function
  • Added more information for computer object:
    •  Manufacturer – example : Microsoft Corporation
    • OSCaption – example : Microsoft Windows 7 Professional
    • VirtualMachine  : True or False
    • OSArchitecture – example : 64-bit

Example 1

.\Ping-Report-v2.ps1 

The script returns a PS object similar to:

ping10

Example 2

.\Ping-Report-v2.ps1 -ComputerName $env:COMPUTERNAME,bla1,p-2012r2-sb1

Possible output:

ping09

This example shows output when a computer is down, and when the script is run under a user context that has no permission/access to query the target computer(s)

Example 3

The same can be done reading the computer list from a CVS file as in:

Import-Csv .\Computerlist.csv | 
  % { .\Ping-Report-v2.ps1 $_.ComputerName }

The input CSV file may look like:

ping05

Example 4

The output can be exported to CSV to file as in:

Import-Csv .\Computerlist.csv | 
  % { .\Ping-Report-v2.ps1 $_.ComputerName } | 
    select ComputerName, Status, OSCaption, VirtualMachine, IPAddress |
      Export-Csv z:report1.csv -NoType

ping07b

Example 5

.\Ping-Report-v2.ps1 V-WIN7PROX64,bla1,V-WIN7PROX64,p-2012r2-sb1 | 
    select ComputerName, Status, OSCaption, VirtualMachine, IPAddress | FT -a

ping08

 

 

StorSimple 8k series as a backup target?


19 December 2016

After a conference call with Microsoft Azure StorSimple product team, they explained:

  •  “The maximum recommended full backup size when using an 8100 as a primary backup target is 10TiB. The maximum recommended full backup size when using an 8600 as a primary backup target is 20TiB”
  • “Backups will be written to array, such that they reside entirely within the local storage capacity”

Microsoft acknowledge the difficulty resulting from the maximum provisionable space being 200 TB on an 8100 device, which limits the ability to over-provision thin-provisioned tiered iSCSI volumes when expecting significant deduplication/compression savings with long term backup copy job Veeam files for example.

Conclusion

  • When used as a primary backup target, StorSimple 8k devices are intended for SMB clients with backup files under 10TB/20TB for the 8100/8600 models respectively
  •  Compared to using an Azure A4 VM with attached disks (page blobs), StorSimple provides 7-22% cost savings over 5 years

15 December 2016

On 13 December 2016, Microsoft announced the support of using StorSimple 8k devices as a backup target. Many customers have asked for StorSimple to support this workload. StorSimple hybrid cloud storage iSCSI SAN features automated tiering at the block level from its SSD to SAS to Azure tiers. This makes it a perfect fit for Primary Data Set for unstructured data such as file shares. It also features cloud snapshots which provide the additional functionality of data backup and disaster recovery. That’s primary storage, secondary storage (short term backups), long term storage (multiyear retention), off site storage, and multi-site storage, all in one solution.

However, the above features that lend themselves handy to the primary data set/unstructured data pose significant difficulties when trying to use this device as a backup target, such as:

  • Automated tiering: Many backup software packages (like Veeam) would do things like a forward incremental, synthetic full, backup copy job for long term retention. All of which would scan/access files that are typically dozens of TB each. This will cause the device to tier data to Azure and back to the local device in a way that slows things down to a crawl. DPM is even worse; specifically the way it allocates/controls volumes.
  • The arbitrary maximum allocatable space for a device (200TB for an 8100 device for example), makes it practically impossible to use the device as backup target for long term retention.
    • Example: 50 TB volume, need to retain 20 copies for long term backup. Even if change rate is very low and actual bits after deduplication and compression of 20 copies is 60 TB, we cannot provision 20x 50 TB volumes, or a 1 PB volume. Which makes the maximum workload size around 3TB if long term retention requires 20 recovery points. 3TB is way too small of a limit for enterprise clients who simply want to use Azure for long term backup where a single backup file is 10-200 TB.
  • The specific implementation of the backup catalog and who (the backup software versus StorSimple Manager service) has it.
  • Single unified tool for backup/recovery – now we have to use the backup software and StorSimple Manager, which do not communicate and are not aware of each other
  • Granular recoveries (single file/folder). Currently to recover a single file from snapshot, we must clone the entire volume.

In this article published 6 December 2016, Microsoft lays out their reference architecture for using StorSimple 8k device as a Primary Backup Target for Veeam

primarybackuptargetlogicaldiagram

There’s a number of best practices relating to how to configure Veeam and StorSimple in this use case, such as disabling deuplication, compression, and encryption on the Veeam side, dedicating the StorSimple device for the backup workload, …

The interesting part comes in when you look at scalability. Here’s Microsoft’s listed example of a 1 TB workload:

ss-backup-target03

This architecture suggests provisioning 5*5TB volumes for the daily backups and a 26TB volume for the weekly, monthly, and annual backups:

ss-backup-target04

This 1:26 ratio between the Primary Data Set and Vol6 used for the weekly, monthly, and annual backups suggests that the maximum supported Primary Data Set is 2.46 TB (maximum volume size is 64 TB) !!!???

ss-backup-target05

This reference architecture suggests that this solution may not work for a file share that is larger than 2.5TB or may need to be expanded beyond 2.5TB

Furthermore, this reference architecture suggests that the maximum Primary Data Set cannot exceed 2.66TB on an 8100 device, which has 200TB maximum allocatable capacity, reserving 64TB to be able to restore the 64TB Vol6

ss-backup-target06

It also suggests that the maximum Primary Data Set cannot exceed 8.55TB on an 8600 device, which has 500TB maximum allocatable capacity, reserving 64TB to be able to restore the 64TB Vol6

ss-backup-target07

Even if we consider cloud snapshots to be used only in case of total device loss – disaster recovery, and we allocate the maximum device capacity, the 8100 and 8600 devices can accommodate 3.93TB and 9.81TB respectively:

ss-backup-target08

Conclusion:

Although the allocation of 51TB of space to backup 1 TB of data resolves the tiering issue noted above, it significantly erodes the value proposition provided by StorSimple.

Upgrading Server 2012 R2 to Server 2016 and Storage Spaces


Server 2016 has enhanced and added new features to Storage Spaces. Most notably is the introduction of Storage Spaces Direct, Storage Replica, and Storage QoS. This post explores upgrading a physical Server 2012 R2 that uses mirrored tiered storage space.

After installing Server 2016 (Desktop Experience), and choosing to keep ‘nothing’

server2016-34

In Server Manager, File and Storage Services\Volumes\Storage Pools, we see the old Storage Pool from the prior installation of Server 2012 R2

server2016-17

To recover the Storage Pool, its virtual disks, and all data follow these steps:

  1. Set Read-Write access server2016-19
  2. Upgrade the Storage Pool Version server2016-18Note that this step is irreversible
    server2016-20
  3.  Right click on each virtual disk and attach it server2016-21
  4. Finally, in Disk Management, right click on each virtual disk and online it
    server2016-23

The virtual disks retain the drive letters and volume labels assigned to them in the old 2012 R2 server. All data is intact.

 

Windows Server 2016 GUI options


Server 2016 comes with 2 options:

  1. Windows Server 2016, and
  2. Windows Server 2016 (Desktop Experience)

server2016-25

server2016-24

The first option has no GUI. This was known as (Server Core Installation) in Server 2012.

server2016-26

The second option has a Graphical User Interface (GUI).

This is not just a change in labels. In Server 2012 R2, the GUI was just a set of features that can be uninstalled and reinstalled as needed. This appears not to be the case in Server 2016.

Here is a feature list from a physical Server 2012 R2 Data Center with GUI:

server2016-28

and here’s the same list from a physical Server 2016 Data Center with GUI:

server2016-27

Note that the following features appear not to exist anymore in Server 2016:

  • User-Interfaces-Infra
  • Server-Gui-Mgmt-Infra
  • Server-Gui-Shell

In a Server 2016 Data Center (Core) installation, attempting to install the GUI from PowerShell fails. This portion of a PowerShell transcript shows the Server 2016 Edition:

server2016-29

After mounting the ISO

server2016-30

and identifying the image ID in the WIM file for Data Center edition

server2016-31

attempting to install GUI fails:

server2016-32

GUI options are not even available in a 2016 Core installation:

server2016-33

Summary:

Unlike Server 2012, in Server 2016 it appears a Server Core installation cannot be turned into a GUI installation or vice versa.