General

System Center Configuration Manager SCCM Collection Queries

Some of the useful queries we used and still being used;

Client Collections

Collection for all Workstations.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client

from SMS_R_System where SMS_R_System.OperatingSystemNameandVersion like

“%workstation%”

 

Collection of all Windows 10 clients.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType,

SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%workstation 10.0%”

Collection of all Windows 8.1 clients.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%workstation 6.3%”

Collection of all Windows 8 clients.

This query need to be limited to the All Workstations collection to work. If not it will also have Windows Server 2012 members as they share the same version number.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%workstation 6.2%”

 

Collection of all Windows 7 clients.

This query need to be limited to the All Workstations collection to work. If not it will also have Windows Server 2008 R2 members as they share the same version number.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%workstation 6.1%”

 

Collection for all Servers.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client

from SMS_R_System where SMS_R_System.OperatingSystemNameandVersion like

“%server%”

 

Collection of all Windows 2012 R2 Servers.

  select

SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%Server 6.3%”

 

Collection of all Windows 2012 Servers.

  select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%Server 6.2%”

 

Collection of all Windows 2008 R2 Servers.

  select SMS_R_SYSTEM.ResourceID, SMS_R_SYSTEM.ResourceType, SMS_R_SYSTEM.Name, SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup, SMS_R_SYSTEM.Client from

SMS_R_System

where SMS_R_System.OperatingSystemNameandVersion like “%Server 6.1%”

 

Collection of all Domain Controllers.

This query requires that the config manager client is installed and hardware inventory is turned on.

  select *  from  SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId

where SMS_G_System_COMPUTER_SYSTEM.Roles like “%Domain_Controller%”

All Hewlet-Packard Systems

  select

SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,

SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client

from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on

SMS_G_System_COMPUTER_SYSTEM.ResourceId = SMS_R_System.ResourceId

where SMS_G_System_COMPUTER_SYSTEM.Manufacturer like “Hewlett-Packard%”

or SMS_G_System_COMPUTER_SYSTEM.Manufacturer like “HP%”

All Physical Systems

  select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,

SMS_R_SYSTEM.SMSUniqueIdentifier,

SMS_R_SYSTEM.ResourceDomainORWorkgroup,

SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceID = SMS_R_System.ResourceId

where SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes = “23” or

SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes = “17”

 

SQL Server Collection Query

select SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.Name, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.Client from SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId inner join SMS_G_System_ADD_REMOVE_PROGRAMS_64 on SMS_G_System_ADD_REMOVE_PROGRAMS_64.ResourceID = SMS_R_System.ResourceId where SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like “Microsoft SQL Server 200%” or SMS_G_System_ADD_REMOVE_PROGRAMS_64.DisplayName like “Microsoft SQL Server 20%”

 

All Windows Workstations

Select

SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System where SMS_R_System.OperatingSystemNameandVersion like ‘Microsoft Windows NT%Workstation%’

 

All Systems with HyperV Role

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System  inner join SMS_G_System_SERVICE on SMS_G_System_SERVICE.ResourceID = SMS_R_System.ResourceId  where SMS_G_System_SERVICE.DisplayName like “Hyper-V Virtual Machine Management”

 

SCCM All Laptops Collection

select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from SMS_R_System inner join SMS_G_System_SYSTEM_ENCLOSURE on SMS_G_System_SYSTEM_ENCLOSURE.ResourceID = SMS_R_System.ResourceId where   SMS_G_System_SYSTEM_ENCLOSURE.ChassisTypes in ( “8”, “9”, “10”, “14” )

 

 

 

 

 

Advertisements
General

Provisioning Services – Cache Options

How to access these options?

These cache options I have previously mentioned can be accessed via the properties of the vDisk. (To create one go to Store, right click and choose create a new vDisk)

PVS1

Under access mode, if it is showing Private Image, cache type will be grayed out which is saying vDisk is currently in used and you can’t change this option. When you change the Access mode to Standard Image then you have options available;

PVS2

General

Windows Server 2016 Editions, Pricing, Availability, Features

Server-2016-TP5

Windows Server 2016 is the next version of Microsoft’s server operating system. Being developed in line with Windows 10, its first technical preview came out in October 2014. The OS is still in beta stage but Microsoft has finally confirmed its final release.

Along with this news, Microsoft has also delineated how Windows Server 2016 will be serviced going forward. In earlier versions of Windows Server, it was serviced and supported with a “5+5” model meaning that there will be 5 years of mainstream support and 5 years of extended support. This continues with Windows Server 2016 as well, the only difference being the nomenclature. Customers who choose to install full Windows Server 2016 with a Desktop GUI or Server Core will maintain the same servicing experience which will be known as Long Term Servicing Branch (LTSB).

Windows Server 2016 Editions

windows-server-2016-editions

Windows Server comes in 3 main editions:

  1. Datacenter Edition: Donning all the basic capabilities of Windows Server, this edition will provide substantial efficacy to the Organization with a requirement for unlimited virtualization coupled with robust new features.
  2. Standard Edition: Quintessential for Organization with a need for limited virtualization, this model brings forth a general purpose yet a sturdy Server Operating System.
  3. Essentials: Targeted for smaller Organization comprising no more than 50 users, this edition provides limited capabilities as per your requirement.

Windows Server 2016 MultiPoint Premium Server, Windows Storage Server 2016 and Microsoft Hyper-V Server 2016 are the other editions.

General, Powershell

Get Last Reboot Date and Time – PowerShell

One of the most common questions asked when working with projects either for patching or testing or any other reason is when servers last rebooted. I have found the WMI class which will give us what we need.

Win32_OperatingSystem

So what can I get out of this class?

Get-WMIObject Win32_OperatingSystem | Get-Member

Get-CimInstance Win32_OperatingSystem | Get-Member

There is a difference we will see. Look at the definitions. This will reflect to their output.

LASTWMI

LastCIM

and LastBootUpTime what we need and we need to pull this info out of here;

Get-WMIObject -ClassName win32_OperatingSystem | select csname, lastbootuptime

csname                 lastbootuptime
——                  ————–
USER-PC             20160707090526.982130+060

And

Get-CimInstance -ClassName win32_OperatingSystem | select csname, lastbootuptime

csname                  lastbootuptime
——                   ————–
USER-PC               7/7/2016 9:05:26 AM

So looks like we need to convert the time if you use Get-WMIObject

>$wmi = gwmi win32_operatingsystem
>$wmi.ConvertToDateTime($wmi.LastBootUpTime)

or

$LastBootUpTime = Gwmi Win32_OperatingSystem -Comp server01 | Select -Exp LastBootUpTime
[System.Management.ManagementDateTimeConverter]::ToDateTime($LastBootUpTime)
or

>gwmi win32_operatingsystem | %{ $_.ConvertToDateTime($_.LastBootUpTime) }

or

>$BootTime = Invoke-Command -Cn server01, server02`
  -Command { (gwmi win32_operatingsystem).lastbootuptime }
>$BootTime | foreach { ([wmi]'').ConvertToDateTime($_) }

Why do you need to go through these conversions, just use Get-CimInstance...

>$BootTimes = Get-CimInstance -Cn server1, server2-Class Win32_OperatingSystem |
    Select PSComputerName, LastBootUpTime

>$BootTimes | Format-Table -AutoSize

PSComputerName LastBootUpTime       
-------------- --------------       
server1        8/18/2016 15:40:32 PM 
server2        8/19/2016 20:50:53 PM
 If you have got a few servers put them in a txt file  (serverlist.txt) and use;

$compname = Get-Content -Path C:\serverlist.txt
foreach ($comp in $compname) {
    Get-WmiObject win32_operatingsystem -ComputerName $comp | '
select CSName, @{LABEL='LastBootUpTime';'
EXPRESSION={$_.ConverttoDateTime($_.lastbootuptime)}}

}
 

 

General

Blob copy between Storage Accounts in Azure

Previously I copied a vhd file called Nano2016.vhd from my on-premises server in to Azure. Now I need to use this file for my other storage account. So it means I need to copy this file in to my other storage account.

StorageAccount01  —————–> StorageAccount02

vhds container        —————–> uploads container (will be created during copy)

The script I am going to run is;

$vhdName = “Nano2016.vhd”
$srcContainer = “vhds”
$destContainer = “uploads”
$srcStorageAccount = “Storageaccount01”
$destStorageAccount = “StorageAccount02”

$srcStorageKey = (Get-AzureStorageKey -StorageAccountName` $srcStorageAccount).Primary
$destStorageKey = (Get-AzureStorageKey -StorageAccountName` $destStorageAccount).Primary
$srcContext = New-AzureStorageContext –StorageAccountName` $srcStorageAccount `
-StorageAccountKey $srcStorageKey

$destContext = New-AzureStorageContext –StorageAccountName ` $destStorageAccount `
-StorageAccountKey $destStorageKey

New-AzureStorageContainer -Name $destContainer `
-Context $destContext
$copiedBlob = Start-AzureStorageBlobCopy -SrcBlob $vhdName `
-SrcContainer $srcContainer `
-Context $srcContext `
-DestContainer $destContainer `
-DestBlob $vhdName `
-DestContext $destContext

$copiedBlob | Get-AzureStorageBlobCopyState

As you see we need to gather some info to such as our file name, source container which our file hosted “vhds”, destination container which in my case it will be “uploads” and will be created during running this script and of course our storage accounts. you can use both Azure portal or powershell for these.

Add-AzureAccount
Get-AzureStorageAccount | Format-Table -Property Label

From Azure Portal

Storage> you can get all the storage accounts and click on your source storage account and then containers to choose your container and the file.

Cap9

and also get your storage account names so that we can use them for our script.

$vhdName = “Nano2016.vhd”
$srcContainer = “vhds”
$destContainer = “uploads”
$srcStorageAccount = “Storageaccount01”
$destStorageAccount = “StorageAccount02”

After that we can run our script. I will run one line at a time to see the steps clearly..

PS C:\Users\user> $vhdName = “Nano2016.vhd”
$srcContainer = “https://storageaccount01.blob.core.windows.net/vhds/”
$destContainer = “https://storageaccount02.blob.core.windows.net/vhds/”
$srcStorageAccount = “storageaccount01”
$destStorageAccount = “storageaccount02”

and

PS C:\Users\user> $srcStorageKey = (Get-AzureStorageKey -StorageAccountName $srcStorageAccount).Primary
PS C:\Users\user> $destStorageKey = (Get-AzureStorageKey -StorageAccountName $destStorageAccount).Primary
PS C:\Users\user> $srcContext = New-AzureStorageContext –StorageAccountName $srcStorageAccount `
-StorageAccountKey $srcStorageKey
PS C:\Users\user> $destContext = New-AzureStorageContext –StorageAccountName $destStorageAccount `
-StorageAccountKey $destStorageKey

Next to create a new container in destination storage account;

PS C:\Users\user> New-AzureStorageContainer -Name $destContainer `
-Context $destContext

Blob End Point: https://storageaccount02.blob.core.windows.net/

Name                     PublicAccess                          LastModified
—-                        ————                      ————
uploads                  Off                                               2/25/2016 12:06:05 PM +00:00

Finally starting copy task;

PS C:\Users\user> $copiedBlob = Start-AzureStorageBlobCopy -SrcBlob $vhdName `
-SrcContainer $srcContainer `
-Context $srcContext `
-DestContainer $destContainer `
-DestBlob $vhdName `
-DestContext $destContext

PS C:\Users\user>

As you see you don’t get any information about copying process…

So we need to run another cmdlet;

PS C:\Users\user> $copiedBlob | Get-AzureStorageBlobCopyState
CopyId : 6557ef45-b677-4bbe-92b5-b9888676acf6
CompletionTime :
Status : Pending   <————
Source : https://storageaccount01.blob.core.windows.net/vhds/Nano2016.vhd?sv=2015-04-05&sr=b&sig=a4cENt%2BLQGVJDoAUs5Pz42q2hHExN
wTW557lN%2BxfUlM%3D&se=2016-03-03T12:06:15Z&sp=r
BytesCopied : 0
TotalBytes : 107374182912
StatusDescription :

Or just go to Azure Portal > Storage > Destination Storage Account > Container

in my case I can see a new contaier “uploads” been created and my file is there.

Capture223

And again if you run;

PS C:\Users\user> $copiedBlob | Get-AzureStorageBlobCopyState

CopyId : 6557ef45-b677-4bbe-92b5-b9888676acf6
CompletionTime : 2/25/2016 12:08:46 PM +00:00
Status : Success  <—————-
Source : https://storageaccount02.blob.core.windows.net/vhds/Nano2016.vhd?sv=2015-04-05&sr=b&sig=a4cENt%2BLQGVJDoAUs5Pz42q2hHExN
wTW557lN%2BxfUlM%3D&se=2016-03-03T12:06:15Z&sp=r
BytesCopied : 107374182912
TotalBytes : 107374182912
StatusDescription :

As you see the status has changed to Success from Pending…

Let’s review the parameters in the preceding example:
■■ The SrcBlob parameter expects the file name of source file to start copying.
■■ The SrcContainer parameter is the container the source file resides in.
■■ The Context parameter accepts a context object created by the New-AzureStorageContext cmdlet. The context has the storage account name and key for the source storage account and is used for authentication.
■■ The DestContainer is the destination container to copy the blob to. The call will fail if
this container does not exist on the destination storage account.
■■ The DestBlob parameter is the filename of the blob on the destination storage account.
The destination blob name does not have to be the same as the source.
■■ The DestContext parameter also accepts a context object created with the details of
the destination storage account including the authentication key.

P:S. To copy between storage accounts in separate subscriptions, you need to call Select-AzureSubscription between the calls to Get-AzureStorageKey to switch to the alternate subscription.