Monday, 13 November 2017

Read a REG_EXPAND_SZ value from the registry using PowerShell

The Get-Item PowerShell cmdlet is nice and easy to use to get a registry key or value. Here's how we get a key.

$key = Get-Item -Path "Registry::HKEY_LOCAL_MACHINE\Software\TestKey"

But if you want to get the value type, or the raw unexpanded REG_EXPAND_SZ value things get a bit awkward as the Get-Item cmdlet does not return this information. Luckily the registry key that is returned is actually a Microsoft.Win32.RegistryKey object so you can use the following method of that class.

$key.GetValueKind("New Value #6")
Returns "ExpandedString"

You can also read the raw value of a REG_EXPAND_SZ value using the following

$key .GetValue("New Value #6", [System.String]::Empty [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames

Wednesday, 1 November 2017

Get-WebBinding PowerShell cmdlet gives "Value does not fall within the expected range" error if any of the bindings use the central certificate store (CCS).

When using the Get-WebBinding PowerShell you may see the error "Value does not fall within the expected range" error  if any of the bindings use the central certificate store (CCS).

Value does not fall within the expected range.
    + CategoryInfo          : NotSpecified: (:) [Select-Object], ArgumentException
    + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.SelectObjectCommand

This error only occurs  if you perform the following locally

Get-WebBinding|SELECT *

The error also occurs if you try and execute the command using a PowerShell remoting session as the object has to be serialized.

Strangely the cmdlet does correctly return all individual properties. The solution when running remotely using C# is to select only the properties you require by calling ExecuteScript and running
Get-WebBinding|SELECT BindingString etc

Wednesday, 25 October 2017

Windows Task Scheduler - Value does not fall within the expected range.

When you create a scheduled task trigger using the Windows Task Scheduler you may see the error "Value does not fall within the expected range".

Whilst this looks like a serious error.

The issue appears to be when you create a "Monthly" scheduled task on specific days and tick the "<Select all days>" option.

Be warned the task is not updated, however if you double click the trigger again the user interface will have corrected itself by unticking the <Select all days> option, but leaving all of the days selected. You can then click OK and OK again and the task will be updated.

You can also manually check each of the days in the list.

This is the latest in a few issues I've found with the Windows Task Scheduler, as documented in this blog.

Tuesday, 24 October 2017

Not all scheduled tasks show up when running Get-ScheduledTask, certain tasks are missing

When you run the Get-ScheduledTask command you notice that some of the tasks are missing, however you can see these tasks in the Task Scheduler Library.

This can be caused if you have UAC enabled or are logged on as a user who is not an administrator.

Ensure that you right click the PowerShell link and Run as Administrator.

The difference can be seen here

Wednesday, 18 October 2017

Get-ScheduledTask does not return monthly, or monthly day of week triggers.

So having worked with the Task Scheduler Library in Windows over the last few weeks it's a real problem area of Windows

I've already mentioned the issue that deprecated features still appear in the user interface.

The next area to note is that the Get-ScheduledTask PowerShell cmdlet is not fully functional. If you create a scheduled task with a monthly trigger (or a monthly day of week trigger) this cannot be read using the cmdlet.

Instead of a fully fledged object like you would receive from the other trigger types you instead receive the base object.


Enabled               : True
EndBoundary           :
ExecutionTimeLimit    :
Id                    :
Repetition            : MSFT_TaskRepetitionPattern
StartBoundary         : 2017-10-18T19:31:14
PSComputerName        :
CimClass              : Root/Microsoft/Windows/TaskScheduler:MSFT_TaskTrigger
CimInstanceProperties : {Enabled, EndBoundary, ExecutionTimeLimit, Id...}
CimSystemProperties   : Microsoft.Management.Infrastructure.CimSystemProperties

I was hoping that the limitation was with the PowerShell cmdlets however on checking it seems that the limitation is with the underlying WMI in the ROOT\Microsoft\Windows\TaskScheduler namespace.

The only option in this case is to parse the XML configuration files directly. Not pleasant.

Friday, 13 October 2017

An error has occurred for task 'name'. Error message: The following error was reported: 2147750704. When creating a scheduled task in Windows 2012 or above.

When you create a scheduled task in Windows you notice that the Send an e-mail and Display a message tasks are marked as "deprecated".

You can no longer create these task types and the following error is shown

"An error has occurred for task 'name'. Error message: The following error was reported: 2147750704".

I'm really not sure why Microsoft didn't remove the UI options, it seems strange to have gutted the functionality but leave the options in the user interface.

If you want to send an email you can schedule to Start a program and use the Send-MailMessage PowerShell cmdlet.

Monday, 2 October 2017

Document Azure tenants with Microsoft Live accounts or multi-factor authentication

Our network and cloud documentation tool XIA Configuration is getting a new update.

As our product runs as a Windows service customers have previously had issues when trying to scan an Azure environment by logging on with a Microsoft Live account or with two-factor authentication.

The new version will include a stand alone tool for scanning Azure tenants

The tool operates in a similar way to the standard Azure scan agent.

This will run interactively and display the standard Azure login dialog so that you can login using your normal credentials.

You can then save the output and import it directly into the XIA Configuration Server.