retrieving RDS license - powershell

I have a question, iam running a PowerShell command to retrieved RDS LicenseKeyPack details, according to win32-tslicensekeypack KeyPackType should a number between 0 and 6, yet i am getting 7 on some outputs. What dose this mean?.
Example output:
KeyPackId : 3
KeyPackType : 2
ProductVersion : Windows Server 2016
TypeAndModel : RDS Per User CAL
AvailableLicenses : 48
IssuedLicenses : 1202
ExpirationDate : 20380101000000.000000-000
KeyPackId : 5
KeyPackType : 7
ProductVersion : Windows Server 2012
TypeAndModel : RDS Per User CAL
AvailableLicenses : 0
IssuedLicenses : 1
ExpirationDate : 20380119031407.000000-000
KeyPackId : 7
KeyPackType : 7
ProductVersion : Windows Server 2016
TypeAndModel : RDS Per User CAL
AvailableLicenses : 0
IssuedLicenses : 49
ExpirationDate : 20380119031407.000000-000"

Related

MCU damaged after FLASH->OPTR register changed

I have changed STM32G431CBT6's default BOOT0/PB8 pin disable via changed FLASH->OPTR register
nswboot0 bit from factory default 1 to 0, however after that I have already damaged (or something else such as locked) 3 MCUs.
Now connect with STM32CubeProgrammer, it's reject with below messages.
16:37:24 : Disconnected from device.
16:37:25 : ST-LINK SN : 50FF73064986495117442387
16:37:25 : ST-LINK FW : V2J37S7
16:37:25 : Board : --
16:37:25 : Voltage : 3.24V
16:37:25 : SWD freq : 4000 KHz
16:37:25 : Connect mode: Normal
16:37:25 : Reset mode : Software reset
16:37:25 : Device ID : 0x468
16:37:25 : Revision ID : Rev Y
16:37:25 : UPLOADING OPTION BYTES DATA ...
16:37:25 : Bank : 0x00
16:37:25 : Address : 0x40022020
16:37:25 : Size : 20 Bytes
16:37:25 : Bank : 0x01
16:37:25 : Address : 0x40022070
16:37:25 : Size : 4 Bytes
16:37:25 : UPLOADING ...
16:37:25 : Size : 1024 Bytes
16:37:25 : Address : 0x8000000
16:37:25 : Read progress:
16:37:25 : Error: Data read failed
Regards,
Tiger

How can I filter .content from a invoke-webrequest command

I have an internal web app that provides connection statistics. I am trying to use PS to collect those statistics, which are in .conent. The .content property has a lot of other values I am trying to filter out and I haven't been very successful.
My Command:
invoke-webrequest -URI http://<my internal web site> | Select-Object -ExpandProperty Content
Returned Results:
Greetings from live node: server-name [ FQDN ] , serving at port: 443 since [4 days, 0 hour, 3
3 minutes, 33 seconds] with following settings:
IN_MEMORY_MESSAGE_LIFE_IN_HOURS : 1
DELIVERY_GRACE_WINDOW_IN_SECONDS : 10
BUILD_NUMBER : 4
STATISTICS_LOG_FREQUENCY_IN_MINUTES : 0
HEARTBEAT_INTERVAL_IN_MINUTES : 2
CLUSTERING_MODE : IMPLICIT
CLEAN_ORPHANED_SESSIONS : Y
OFFLOAD_SSL : Y
SERVICE_HOST : 192.168.1.1
REQUEST_TIMEOUT_MILLIS : 3000
SERVICE_PORT : 443
VALIDATE_REQUEST_CONTENT_TYPE : N
APP_BROADCAST_LIFE_IN_MINUTES : 1
DEFAULT_MESSAGE_LIFE_IN_DAYS : 1
VERSION : release/2008
ENABLE_IDLER_STATISTICS : Y
ORIGIN_STATS_EXPIRY_IN_MINUTES : 60
INCLUDE_CACHE_CONTROL_HEADER_IN_HEALTH_CHECK : N
DATABASE_PROVIDER : INMEMORY
QUEUEMONITOR_THREADPOOLSIZE : 100
BUILD_DATE : Mon 27 Jul 2020 10:02:44 AM EDT -0400
BUILD_PLAN : AWCM-AWCM302-JOB1-4
Persistence Store Type:INMEMORY , status: live
Current Active Sessions: 6
They only line I care about is "Current Active Sessions: 6" and really all I care about is the numerical value which I will use in a test later in the script.
How can I just grab the one value I need?
$iwr=invoke-webrequest -URI http://<my internal web site> |
Select-Object -ExpandProperty Content
$cas=$iwr -split [System.Environment]::NewLine |
Select-String -Pattern "Current Active Sessions:\s*(.*)"
$cas.Matches[0].Groups[1].Value
Above code snippet should return 6. Tested using the following (constant) value of $iwr instead of invoke-webrequest:
$iwr=#'
Greetings from live node: server-name [ FQDN ] , serving at port: 443 since [4 days, 0 hour, 3
3 minutes, 33 seconds] with following settings:
IN_MEMORY_MESSAGE_LIFE_IN_HOURS : 1
DELIVERY_GRACE_WINDOW_IN_SECONDS : 10
BUILD_NUMBER : 4
STATISTICS_LOG_FREQUENCY_IN_MINUTES : 0
HEARTBEAT_INTERVAL_IN_MINUTES : 2
CLUSTERING_MODE : IMPLICIT
CLEAN_ORPHANED_SESSIONS : Y
OFFLOAD_SSL : Y
SERVICE_HOST : 192.168.1.1
REQUEST_TIMEOUT_MILLIS : 3000
SERVICE_PORT : 443
VALIDATE_REQUEST_CONTENT_TYPE : N
APP_BROADCAST_LIFE_IN_MINUTES : 1
DEFAULT_MESSAGE_LIFE_IN_DAYS : 1
VERSION : release/2008
ENABLE_IDLER_STATISTICS : Y
ORIGIN_STATS_EXPIRY_IN_MINUTES : 60
INCLUDE_CACHE_CONTROL_HEADER_IN_HEALTH_CHECK : N
DATABASE_PROVIDER : INMEMORY
QUEUEMONITOR_THREADPOOLSIZE : 100
BUILD_DATE : Mon 27 Jul 2020 10:02:44 AM EDT -0400
BUILD_PLAN : AWCM-AWCM302-JOB1-4
Persistence Store Type:INMEMORY , status: live
Current Active Sessions: 6
'#
Try this:
$iwr=invoke-webrequest -URI http://<my internal web site> | Select-Object -ExpandProperty Content
$iwr|Select-String -Pattern "Current Active Sessions: (.*)"

Improving the speed of PowerShell commands in Windows 2016

Example of a problem:
Measure-Command { Get-VMSwitch -SwitchType "External" }
Windows 2012 and 2016 have the same hardware and CPU load is ~50%
Windows Server 2016 (3 external Switches)
Days : 0
Hours : 0
Minutes : 0
Seconds : 6
Milliseconds : 377
Ticks : 63779086
TotalDays : 7.38183865740741E-05
TotalHours : 0.00177164127777778
TotalMinutes : 0.106298476666667
TotalSeconds : 6.3779086
TotalMilliseconds : 6377.9086
Windows Server 2012R2 (3 external Switches)
Days : 0
Hours : 0
Minutes : 0
Seconds : 1
Milliseconds : 376
Ticks : 13762494
TotalDays : 1.59288125E-05
TotalHours : 0.0003822915
TotalMinutes : 0.02293749
TotalSeconds : 1.3762494
TotalMilliseconds : 1376.2494
Windows 2012R2 with a greater or equal CPU load is 6 times faster.
Windows Server 2016 (9 external Switches)
Days : 0
Hours : 0
Minutes : 1
Seconds : 6
Milliseconds : 168
Ticks : 661689307
TotalDays : 0.000765844105324074
TotalHours : 0.0183802585277778
TotalMinutes : 1.10281551166667
TotalSeconds : 66.1689307
TotalMilliseconds : 66168.9307
Windows 2016 slower now 48 times! :)
In Windows 2016 Meltdown/Specter fixes are disabled.
Is there any option for improving the performance of powershell commands in Windows 2016?
Thanks.
Well, I found another solution. It's using bottlenecks through WMI.
The WMI msvm-ethernetswitchport class can provide all the VMSwitches elements, where we can already get the same information that Powershel CMD Get-VMSwitch provides.
https://learn.microsoft.com/en-us/windows/desktop/hyperv_v2/msvm-ethernetswitchport and etc.
A simple example:
ManagementScope scope = new ManagementScope("\\\\.\\ROOT\\virtualization\\v2");
ObjectQuery query = new ObjectQuery("SELECT * FROM Msvm_EthernetSwitchPort");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
foreach (ManagementObject m in queryCollection)
{
Console.WriteLine("DeviceID : {0}", m["DeviceID"]);
Console.WriteLine("ElementName : {0}", m["ElementName"]);
}
It's sad that PowerShell in Windows 2016 runs so slowly...
In fact, through WMI there are so many options how to get this data.
https://learn.microsoft.com/en-us/windows/desktop/hyperv_v2/hyper-v-networking-api

From the SCCM client system, can you list the deployment(s) currently associated to a missing patches?

I'm attempting to build a PowerShell module to help diagnose SCCM issues without giving the system admins access to the SCCM console. The code below currently finds all missing patches on a system but i want to be able to organize them:
Organize patches by deployment name
Display the deployment install deadline
List the Patches missing
Code that gets all missing patches:
$Results = (get-wmiobject -ComputerName $env:ComputerName -query "SELECT * FROM CCM_UpdateStatus" -namespace "root\ccm\SoftwareUpdates\UpdatesStore" | Where-Object {$_.Status -eq "Missing"})
Output Snippet:
__GENUS : 2
__CLASS : CCM_UpdateStatus
__SUPERCLASS :
__DYNASTY : CCM_UpdateStatus
__RELPATH : CCM_UpdateStatus.UniqueId="4ffd2339-7fa5-4716-b64e-78e3dce16d59"
__PROPERTY_COUNT : 15
__DERIVATION : {}
__SERVER : ………………………………
__NAMESPACE : ROOT\ccm\SoftwareUpdates\UpdatesStore
__PATH : \\………………………………\ROOT\ccm\SoftwareUpdates\UpdatesStore:CCM_UpdateStatus.UniqueId="4ffd2339-7fa5-4716-b64e-78e3dce16d59"
Article : 3178662
Bulletin :
ExcludeForStateReporting : False
Language :
ProductID : e6cf1350-c01b-414d-a61f-263d14d133b4
RevisionNumber : 200
ScanTime : 20180320184935.000000+000
Sources : {{7D052A75-2032-4F02-BAC9-9EDA4DBD58DE}}
SourceType : 2
SourceUniqueId : {7D052A75-2032-4F02-BAC9-9EDA4DBD58DE}
SourceVersion : 68
Status : Missing
Title : Update for Microsoft Office 2016 (KB3178662) 32-Bit Edition
UniqueId : 4ffd2339-7fa5-4716-b64e-78e3dce16d59
UpdateClassification : e6cf1350-c01b-414d-a61f-263d14d133b4
PSComputerName : WGC1107B87PH2
I cannot determine how to get a patches associated deployment name or that patches install deployment deadline. Once I can get those two associations I would like to have output something like below:
Baseline Patch Deployment:
Install Deadline: Apr 12, 2018
Missing Patches:
Patch1
Patch2
Patch3
Office 2016 April Patch Deployment:
Install Deadline: Apr 27, 2018
Missing Patches:
Patch1
Patch2
Patch3
Missing but Unapproved Patches:
Install Deadline: None
Missing Patches
Patch1
Patch2
Patch3

How to get a child item into a variable on its own

I am relatively sure this is quite easy to do but my google fu is not running strong
At the moment I am doing:
add-pssnapin windows.serverbackup
get-wbsummary
This returns me:
NextBackupTime : 07/09/2012 12:00:00
NumberOfVersions : 210
LastSuccessfulBackupTime : 06/09/2012 21:00:13
LastSuccessfulBackupTargetPath : \\?\Volume{bf315689-e5ed-11e1-a376-d067e5f384ea}
LastSuccessfulBackupTargetLabel : SBSERVE 2012_08_21 12:20 DISK_01
LastBackupTime : 06/09/2012 21:00:13
LastBackupTarget : SBSERVE 2012_08_21 12:20 DISK_01
DetailedMessage :
LastBackupResultHR : 0
LastBackupResultDetailedHR : 0
CurrentOperationStatus : NoOperationInProgress
What I want to do is get just the result portion (not its title into a variable) so for example $lastbackuptime = 07/09/2012 12:00:00
PS> $wbs = Get-WBSummary
PS> $lastbackuptime = $wbs.NextBackupTime