SQL Server – Integration Services Catalog – Standard Reports – Execution Logs – Permission

Background

One of the managers in our Development group opened up a Ticket last night.

Ticket

The ticket read “Database: sql_server – Issue with table refresh to dev SQL database“.

1 – Daniel Response

As a “smart aleck”, I replied :-

Can you please use SQL Server Management Studio to troubleshoot.
I think as a senior member we gave you ample permissions to troubleshoot.
You want to look at the following:

A) SQL Server Agent
B) SQL Server SSIS Catalog
C) File System Log Folder & Files

If you get permission issue, please let us know and I will create a task and grant you additional permissions.

2 – Manager Response

Daniel,

I have looked at some of this stuff and have not been able to determine what the problem is. It could be that I just don’t know what to look at.

I will reach out the developer to see if she can help me. Please keep this ticket open in case I need to ask for some guidance/assistance from you.

Thanks,
Manager

Issue

Report

Image

report_empty.201816.0102PM.png

Observation

Let us see why she all tallies are coming up zero.

And, all no detail records.

Trouble Shooting

Integration Services Catalogs

Outline

Let use review SSISDB folder permissions for our principal.

Catalog

Catalog – SSISDB

Folder Permissions
Image

folderPermissions.20181116.1107AM.PNG

Explanation

Principal has Read and Read Objects permissions.

Though she has read objects permissions it does not seem to be sufficient.

Remediation

Grant additional permission

In MS SQL Servers v2016 and above, we can grant ssis_logreader role membership to the principal.

Krishnakumar Rukmangathan
Link

The SSIS upgrade to the SSIS 2016 can be an option here. SSIS 2016 brought a new role in the SSISDB, This new ssis_logreader database-level role that you can be used to grant permissions to access the views that contain logging output to users who aren’t administrators.

Ref: Link

Change Code

Outline

  1. SSISDB Database
    • Create new database role
    • Add principals to created database role
    • Alter Code to check role membership

Processing

Create new role

SQL

USE [SSISDB]
GO

if not exists
    (

        select *

        from   sys.database_principals tblSDP

        where  tblSDP.[name] = 'ssis_logreader'
    )
begin

    print 'Create Role - ssis_logreader ...'

    CREATE ROLE [ssis_logreader]
        authorization [dbo];

    print 'Created Role - ssis_logreader '		

end
GO

Add Members to new role

SQL
Syntax

USE [SSISDB]
GO

ALTER ROLE [role]
    ADD MEMBER [principal]
GO

Sample

USE [SSISDB]
GO

ALTER ROLE [ssis_logreader]
    ADD MEMBER [LABDC\psmith]
GO

Amend Code

Outline
  1. Amend the following views
    • Database :- SSISDB
      • Views
        • catalog.event_messages
        • catalog.executions
      • Code original
        • Database Role Membership
          • ssis_admin
            • IS_MEMBER(‘ssis_admin’)
        •  SQL Server Role Member
          • sysadmin
            • IS_SRVROLEMEMBER(‘sysadmin’)
[catalog].[event_messages]
SQL
USE [SSISDB]
GO

ALTER VIEW [catalog].[event_messages]
AS
SELECT     opmsg.[operation_message_id] as [event_message_id],
           opmsg.[operation_id],
           opmsg.[message_time],
           opmsg.[message_type],
           opmsg.[message_source_type],
           opmsg.[message],
           opmsg.[extended_info_id],
           eventmsg.[package_name],
           eventmsg.[event_name],

           message_source_name =
                      CASE
                        WHEN (opmsg.message_source_type = 10) THEN 'ISServerExec'
                        WHEN (opmsg.message_source_type = 20) THEN 'Transact-SQL stored procedure'
                        ELSE eventmsg.message_source_name
                    END,
           eventmsg.[message_source_id],
           eventmsg.[subcomponent_name],
           eventmsg.[package_path],
           eventmsg.[execution_path],
           eventmsg.[threadID],
           eventmsg.[message_code]
FROM       [internal].[operation_messages] opmsg LEFT JOIN [internal].[event_messages] eventmsg
           ON opmsg.[operation_message_id] = eventmsg.[event_message_id]
WHERE     (

                opmsg.[operation_id] in
                (
                    SELECT [id] FROM [internal].[current_user_readable_operations]
                )

                OR (IS_MEMBER('ssis_admin') = 1)

                OR (IS_SRVROLEMEMBER('sysadmin') = 1)

               -- Added on 2018-11-16 11:47 AM
               OR (IS_MEMBER('ssis_logreader') = 1)

           )
GO

[catalog].[event_messages]
SQL

USE [SSISDB]
GO

ALTER VIEW [catalog].[executions]
AS
SELECT     execs.[execution_id],
           execs.[folder_name],
           execs.[project_name],
           execs.[package_name],
           execs.[reference_id],
           execs.[reference_type],
           execs.[environment_folder_name],
           execs.[environment_name],
           execs.[project_lsn],
           execs.[executed_as_sid],
           execs.[executed_as_name],
           execs.[use32bitruntime],
           opers.[operation_type],
           opers.[created_time],
           opers.[object_type],
           opers.[object_id],
           opers.[status],
           opers.[start_time],
           opers.[end_time],
           opers.[caller_sid],
           opers.[caller_name],
           opers.[process_id],
           opers.[stopped_by_sid],
           opers.[stopped_by_name],
           opers.[operation_guid] as [dump_id],
           opers.[server_name],
           opers.[machine_name],
           ossysinfos.[total_physical_memory_kb],
           ossysinfos.[available_physical_memory_kb],
           ossysinfos.[total_page_file_kb],
           ossysinfos.[available_page_file_kb],
           ossysinfos.[cpu_count]
FROM       [internal].[executions] execs INNER JOIN [internal].[operations] opers
           ON execs.[execution_id]= opers.[operation_id]
           LEFT JOIN [internal].[operation_os_sys_info] ossysinfos
           ON ossysinfos.[operation_id]= execs.[execution_id]
WHERE      (
                opers.[operation_id] in
                        (
                           SELECT id
                           FROM [internal].[current_user_readable_operations]
                        )

                OR (IS_MEMBER('ssis_admin') = 1)

                OR (IS_SRVROLEMEMBER('sysadmin') = 1)

               -- Added on 2018-11-16 11:51 AM
                OR (IS_MEMBER('ssis_logreader') = 1)

            )

GO

Validation

Once the changes outlined above are done, one can validate by taken upon the user of the user and try to access the view.

SQL


EXECUTE AS LOGIN = 'LAB\dog';

     select top 100 *
     from [catalog].[executions]
     order by
          1 desc

revert

Output

Output – No Access

executeAs.noAccess.20181116.1247PM.PNG

Output – Sufficient Access

executeAs.sufficientAccess.20181116.1250PM

 

Summary

Revising Microsoft’s code should not be not taken lightly.

But, I think in this case there is a bit of justification.

Those are :-

  1. There is no error message when the user tries to access the reports.
    • The report skeleton is still present
    • It is just that records are filtered out
  2. Other remediation choices such as granting membership in ssis-admin ( database role ) and sysadmin ( Sql Instance Role) are more high bar

References

  1. Microsoft
    • Microsoft Developer
      • SQL BI / Data Access Technologies
        ( SSIS, SSRS, SSAS, Data Access, POWER BI, PBI RS, Azure AS, SSMA, LINQ, System.Data … )

        • How a non-Admin users of SSIS 2012/2014 can view SSIS Execution Reports
          Link
  2. SQL Server Central
    • Home»SQL Server 2012»SQL 2012 – General»SSIS Execution Reports Permission
      • SSIS Execution Reports Permission
        Link

AWS/IAM – CLI :- Multi-Factor Authentication

Background

If you happen to secure AWS Resources with Multi-Factor authentication, and you are working within the Command Line Interface, you do have bit of jumping on a trampoline to do.

Outline

  1. Multi-Factor Device – Review Settings
    • Check MFA Status
      • Is it MFA hardware device or is it Virtual
    • Get Device’s ARN
  2. Issue and capture of “sts get-session-token
  3. Set Session Token
  4. Attempt to access resource

Processing

Multi-Factor Device – Review Settings

Outline

  1. Access IAM Console ( Link )
  2. Search for user
    • Enter username
  3. Select sought user
  4. User Summary Screen comes up
  5. Access “Security Credentials” Tab
  6. The “Security Credentials” tab appears
    • Note the following
      • Assigned MFA Device
      • Assign MFA Type
        • Virtual in our case

Images

Search for user

IAM.Users.searchUser.20181115.0421PM.PNG

User Summary

IAM.Users.user.Summary.20181115.0423PM.PNG

User – Security Credentials

IAM.Users.user.SecurityCredentials.20181115.0426PM.PNG

Data Set

  1. Assigned MFA device
    • arn:aws:iam::[ID]:mfa/[account-id] (Virtual) | Manage
      • id
      • Virtual

Issue & Capture Output of “sts get-session-token

Outline

  1. Issue sts get-session-token
  2. Capture output

Code


 setlocal

REM How do I use an MFA token to authenticate access to my AWS resources through the AWS CLI?
REM https://aws.amazon.com/premiumsupport/knowledge-center/authenticate-mfa-cli/

REM Assigned MFA device
REM Is it an MFA hardware device or is it Virtual
rem set _ARNUser = arn:aws:iam::userid:user/awsauth/dadeniji
set _userid=11101
set _ARNmfa=arn:aws:iam::%_userid%:mfa/dadeniji

set _durationInSeconds=129600

REM **********************************************************************************
REAM Read token from device -- cellphone etc
REM **********************************************************************************
set _codeFromToken=506694

rem aws sts get-session-token --serial-number arn-of-the-mfa-device --token-code code-from-token

aws sts get-session-token --serial-number %_ARNmfa% --duration-seconds %_durationInSeconds% --token-code %_codeFromToken% 

endlocal

Output

sts.get-session-token.20181115.0439PM.PNG

Explanation

Please capture the output :-

  1. Credentials
    • AccessKeyId
    • SecretAccessKey
    • SessionToken

Set Session Token

Outline

  1. Set Session Token

Code


set AWS_ACCESS_KEY_ID=ANTELOPE
set AWS_SECRET_ACCESS_KEY=SAK
set AWS_SESSION_TOKEN=Patti

Access Resource

Outline

  1. Access Resource
    • Access S3 bucket
    • Access RDS DB Resource

Sample

Sample – S3 Bucket

Code
aws s3 ls --profile savanna

Output

request.S3.20181115.0452PM.PNG

 

References

  1. Amazon
    • AWS
      • CLI
        • MFA
          • How do I use an MFA token to authenticate access to my AWS resources through the AWS CLI?
            Link
      • Directory Services
        • To establish a trust relationship for an existing role to AWS Directory Service
          Link
      • Granting a User Permissions to Switch Roles
        • id_roles_use_permissions-to-switch

          Link

SQL Server – Statistics – Fake Stats

Background

Quick follow-up from our last post.

Referenced Post

SQL Server – Clone Database – Schema & Statistics
Link

Statistics

Statistics helps SQL Server pick the most efficient query plan.

Alternatives

If we cannot :-

  1. Restore Database
    • Cannot, due to
      • Size
      • Data Sensitivity
  2. DBCC Clone Database
    • Cannot, due to
      • Need only a couple of tables
      • SQL Server Version does not support DBCC Cloning
        • To use DBCC Cloning, SQL Server has to be v2012 or above
  3. SQL Server Management Studio ( SSMS ) / Script Statistics
    • Cannot, due to
      • SQL Server Version does not Statistics reverse engineering

Create Artificial Statistics

Outline

  1. Source Instance
    • Generate Schema
      • Determine table level statistics
        • Number of Records
        • page Consumption
  2. Destination Instance
    • Replay Schema
    • Apply Table Statistics

Source Instance

Generate Schema

Using Sql Server Management Studio ( SSMS), Generate Table Schema, Indexes, and Constraints

Determine Table Statistics

Number of Records
SQL

select
        [table]
            = quotename(tblSS.name)
              + '.'
              + quoteName(tblSO.name)

        , [rowCount]
            = tblSP.[rows]

from   sys.schemas tblSS

inner join sys.tables tblSO

    on tblSS.schema_id = tblSO.schema_id

inner join sys.indexes tblSI

    on tblSO.object_id = tblSI.object_id

inner join sys.partitions tblSP

    on  tblSI.object_id = tblSP.object_id

    and tblSI.index_id = tblSP.index_id

where  tblSO.[type] = 'U'

and     tblSI.index_id in (0,1)

order by
        [table] asc

Image

table.rowCount.20181115.1109AM.PNG

Number of Records
SQL
--use [tempdb]
go

select
        [table]
            = quotename(tblSS.name)
              + '.'
              + quoteName(tblSO.name)

        , [rowCount]
            = max(tblSP.[rows])

        , [reservedPageCount]
            = sum(tblDPS.reserved_page_count)

from   sys.schemas tblSS

inner join sys.tables tblSO

    on tblSS.schema_id = tblSO.schema_id

inner join sys.indexes tblSI

    on tblSO.object_id = tblSI.object_id

inner join sys.partitions tblSP

    on  tblSI.object_id = tblSP.object_id

    and tblSI.index_id = tblSP.index_id

inner join sys.dm_db_partition_stats tblDPS

    on  tblSI.object_id = tblDPS.object_id

    and tblSI.index_id = tblDPS.index_id

where  tblSO.[type] = 'U'

/*

    and     tblSI.index_id in (0,1)

*/

group by

          tblSI.object_id

        , quotename(tblSS.name)

        , quoteName(tblSO.name)

order by
        [table] asc
<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>
Image

sys.dm_db_partition_stats.20181115.1252PM

Destination Instance

Replay Schema

Using Sql Server Management Studio ( SSMS), replay generated Table Schema, Indexes, and Constraints.

Set Table Statistics

SQL
Syntax
update statistics [schema].[table] with rowcount = [rowCount]<span id="mce_SELREST_start" style="overflow:hidden;line-height:0;"></span>
Sample
update statistics Dimension.Date with rowcount = 500000

Lab

Metadata

Table Statistics

Here is table statistics once the fake stats are applied

table.properties.20181115.11239AM.PNG

Query Plan

Query Plan – Original

queryPlan.Original.20181115.1132AM

Query Plan – Revised

queryPlan.Revised.20181115.1130AM.PNG

Explanation

Faking Statistics gives us a more realistic view of how the query will execute against live data.

SQL Server – Clone Database – Schema & Statistics

Background

Working with my best friend to troubleshoot a non-performant query and so here we go.

Scenario

The database is too big and contains data that should be kept private and so what to do.

DBCC Clone

Outline

  1. Source SQL Instance
    • dbcc  clone
    • Backup resulting database
  2. Destination SQL Instance
    • Restore database
  3. Compare Queries

Source SQL Instance

DBCC Clone

SQL

DBCC CLONEDATABASE 

	(
		  [WideWorldImportersDW]
		, [WideWorldImportersDW_DBCCClone]
	);   

GO
GO

Database Backup

SQL

exec master..xp_create_subdir 'E:\temp'
go

backup database [WideWorldImportersDW_DBCCClone]
to disk = 'E:\temp\WideWorldImportersDW_DBCCClone.bak'
with init, format, stats=1 

GO

Destination SQL Instance

Database Restore

SQL

USE [master]
go

exec master..xp_create_subdir 'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone'
go

exec master..xp_create_subdir 'C:\Microsoft\SQLServer\Logfiles\WideWorldImportersDW_DBCCClone'
go

RESTORE DATABASE [WideWorldImportersDW_DBCCClone] 

FROM  DISK = N'C:\Temp\WideWorldImportersDW_DBCCClone.bak' WITH  FILE = 1

	,  MOVE N'WWI_Primary' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_167133806.mdf'
	,  MOVE N'WWI_UserData' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_UserData_1341343279.ndf'
	,  MOVE N'fg_Partition_Year_Base__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_Base_file_001_4162930605.ndf'
	,  MOVE N'fg_Partition_Year_2010__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2010_file_001_3028494415.ndf'
	,  MOVE N'fg_Partition_Year_2011__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2011_file_001_474007300.ndf'
	,  MOVE N'fg_Partition_Year_2012__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2012_file_001_3961387451.ndf'
	,  MOVE N'fg_Partition_Year_2013__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2013_file_001_2554884830.ndf'
	,  MOVE N'fg_Partition_Year_2014__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2014_file_001_3195214954.ndf'
	,  MOVE N'fg_Partition_Year_2015__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2015_file_001_2796606126.ndf'
	,  MOVE N'fg_Partition_Year_2016__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2016_file_001_2922730419.ndf'
	,  MOVE N'fg_Partition_Year_2017__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2017_file_001_89564842.ndf'
	,  MOVE N'fg_Partition_Year_2018__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2018_file_001_2594545631.ndf'
	,  MOVE N'fg_Partition_Year_2019__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2019_file_001_102789485.ndf'
	,  MOVE N'fg_Partition_Year_2020__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_2020_file_001_2559250543.ndf'
	,  MOVE N'fg_Partition_Year_Null__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_Null_file_001_3677708393.ndf'
	,  MOVE N'fg_Partition_Year_Next__01' TO N'C:\Microsoft\SQLServer\Datafiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_fg_Partition_Year_Next_file_001_2414564952.ndf'
	,  MOVE N'WWI_Log' TO N'C:\Microsoft\SQLServer\Logfiles\WideWorldImportersDW_DBCCClone\WideWorldImportersDW_3476128794.ldf'
	,  NOUNLOAD
	,  STATS = 5

GO

Compare Queries

Outline

  1. Compare Queries
    • Query 1

Compare Queries

Query 1

SQL
set nocount on
go

set statistics io on
go

declare @dateTS datetime
declare @date datetime

set @dateTS = getdate()
set @date = convert(varchar(10), @dateTS, 23)

select
          @dateTS as [@dateTS]
        , @date as [@date]

select top 10 *

from   [Dimension].[Date] tblD

select top 10 *

from   [Dimension].[Date] tblD

where  tblD.[Date] = @date
Output
Output – Source

query1_Source_20181115_0911AM

Output – Destination

query1_Destination_20181115_0912AM

Explanation
  1. We have data from original source
  2. And, not data from the resultant cloned database

 

Query Plan
Query Plan – Destination

queryPlan_Destination_20181115_0853AM

Query Plan – Source

queryPlan_Source_20181115_0905AM.PNG

Statistics IO
Image – Destination

statisticsIO.Destiation.2018115.0855AM

Image – Source

statisticsIO.Source.2018115.0856AM

Explanation
  1. Statistics IO
    • Scan Counts will match
    • Logical & Physical Reads will not
      • As Source has actual data, but destination does not

 

References

  1. Microsoft
    • Docs / SQL / T-SQL / Database Console Commands
      • DBCC CLONEDATABASE (Transact-SQL)

 

Gender Change & Reaching Back

 

Videos

  1. I Want My Sex Back: Transgender people who regretted changing sex (RT Documentary)
    • Profile
      • Billy, Rene and Walt were born male, but they all felt uncomfortable with their sex. So they underwent sex reassignment surgery, believing it would end their distressing condition, which is known as gender dysphoria – feeling uncomfortable with your birth sex. However, becoming female only brought problems, disappointment and regret.
    •  Videos
      • Channel :- RT
        Published On :- 2018-Sept-10
        Link

Reporting Services – Errors – ‘The feature: “Scale-out deployment” is not supported in this edition of Reporting Services. (rsOperationNotSupported)’

Background

Post upgrade of Microsoft’s SQL Server, trying to access Reporting Services, ran into an error.

Error

Error Image

TheFeatureScaleOutDeploymentIsNotSupported.20181111.0342PM.PNG

Error Textual

The feature “Scale-out deployment” is not supported in this edition of Reporting Services.  (rsOperationNotSupported).

Trouble Shooting

Outline

  1. Confirm SQL Server Edition
  2. Review registered encryption keys for the Report Server Instance

Confirm SQL Server Edition

Launch SQL Server Query tool and issue a query that will help determine SQL Server Edition:

Code


select @@version as [version]

Output

Output Image

@@version.20181115.0551AM

Output Textual


Microsoft SQL Server 2017 (RTM-CU12) (KB4464082) - 14.0.3045.24 (X64)
Oct 18 2018 23:11:05
Copyright (C) 2017 Microsoft Corporation
Standard Edition (64-bit) on Windows Server 2012 R2 Standard 6.3  (Build 9600: ) (Hypervisor)

Explanation

  1. We are running SQL Server
    • Marketing :- v2017
    • RTM/Service Pack :- RTM
    • Cumulative Patch :- CU12
    • Edition :- Standard Edition

Review registered encryption keys for the Report Server Instance

using same query tool you used to determine SQL Server’s Version Number, please review the contents of the ReportServer.dbo.keys table.

Code

select *

from [ReportServer].dbo.[Keys]

Output

Output Image

ReportServer.dbo.keys.01.20181111.0342PM [brushedup].png

Explanation

  1. We have three entries
    • Records
      • Installation ID
        • 00000000-0000-0000-0000-000000000000
          • We can skip for now
        • BDEBD908-9B5E-4971-B6A5-0E6EB267A2CA
          • InstanceName = SSRS
            • SSRS is the new instance name for SQL Server Reporting Services
            • And, we can confirm that it is the one post upgrade
          • InstanceName= MSSQLSERVER
            • MSSQLSERVER is pre-upgrade name
            • We can remove it

Remediation

Outline

  1. Backup database table
  2. Remove previous key

Backup database table

Let us backup ReportServer.dbo.keys

Code


if schema_id('dbBackup') is null
begin

create schema [dbBackup] authorization [dboo];

end

select *

into   [ReportServer].[dbBackup].[keys.20181115.0607AM]

from   [ReportServer].[dbo].[keys]

Remove Previous Key

Remove previous key from ReportServer.dbo.keys

Code


delete
from   [ReportServer].[dbo].[keys]
where  InstanceName = 'MSSQLSERVER'

PowerShell – Get Computer name

Background

Wanted to highlight a couple of APIs for retrieving the computer name in Powershell.

Platform

Linux/Cent OS.

 

Outline

  1. Environment Variable
    • Get-ChildItem Env:HOSTNAME
  2. system.environment
    • machineName
  3. system.net.Dns
    • GetHostName
  4. Get-WmiObject ( only works on MS Windows )
    • Win32_ComputerSystem
      • Name

 

Environment Variables

Get-ChildItem Env:

Syntax


pwsh -Command "Get-Childitem Env:"

Output

Get-ChildItem.Env.20181112.0729PM

 

Get-ChildItem Env:HOSTNAME

Syntax


pwsh -Command "Write-Host( (Get-ChildItem Env:HOSTNAME).Value )"

Output

Get-ChildItem.Env.HostName.20181112.0723PM

system.environment

machineName

Syntax


pwsh -Command "Write-Host([system.environment]::machineName)"

Output

system.environment.machineName.20181112.0708PM

system.net.Dns

GetHostName

Syntax


pwsh -Command "Write-Host([system.net.Dns]::GetHostName())

Output

system.net.Dns.GetHostName.20181112.0706PM

 

Get-WmiObject.Win32_ComputerSystem.Name.20181113.0159AM.PNG

Win32_ComputerSystem

Syntax


powershell -Command "Write-Host((Get-WmiObject Win32_ComputerSystem).Name)"

Output

OS – MS Windows

Get-WmiObject.Win32_ComputerSystem.Name.20181113.0159AM.PNG

OS – Linux

Image

Get-WmiObject.Win32_ComputerSystem.Name.Linux.20181113.0203AM

Textual


>pwsh -Command "Write-Host( Write-Host((Get-WmiObject Win32_ComputerSystem).Name))"
Get-WmiObject : The term 'Get-WmiObject' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:25
+ Write-Host( Write-Host((Get-WmiObject Win32_ComputerSystem).Name))
+ ~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-WmiObject:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException