Hello, I have been running the same code previously and I never saw the 3 properties PSComputerName, RunspaceId and PSShowComputerNamereturn return previously but now all of a sudden, I see them. I am stumped as to why?? The only difference was that I was running PS ver 5.0 and now its 5.1.
Please help me understand and eliminate these 3 properties from returning. This has caused my execution time to jump from 3 secs to 45secs approx.
Code and output below:
Invoke-Command -ComputerName SERVER -ScriptBlock {[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
>> $server = New-Object Microsoft.SqlServer.Management.Smo.Server "SERVER"
>> $server.Databases |
>> Select @{label="Server";Expression={$_.Parent.name}},
>> @{Label="DB_ID";Expression={$_.ID}},
>> @{label="Database Name";Expression={$_.Name}},
>> LastLogBackupDate,
>> LastDifferentialBackupDate,
>> LastBackupDate} | Sort-Object DB_ID | Format-Table * -AutoSize
Server DB_ID Database Name LastLogBackupDate LastDifferentialBackupDate LastBackupDate PSComputerName RunspaceId PSShowComputerName
------ ----- ------------- ----------------- -------------------------- -------------- -------------- ---------- ------------------
SERVER 1 master 1/1/0001 12:00:00 AM 1/1/0001 12:00:00 AM 8/15/2018 7:04:00 PM SERVER f79a0d6b-a96d-4aa5-89b2-1bcfed3ad569 True
SERVER 2 tempdb 1/1/0001 12:00:00 AM 1/1/0001 12:00:00 AM 1/1/0001 12:00:00 AM SERVER f79a0d6b-a96d-4aa5-89b2-1bcfed3ad569 True
SERVER 3 model 1/1/0001 12:00:00 AM 8/15/2018 7:01:28 PM 8/10/2018 7:01:19 PM SERVER f79a0d6b-a96d-4aa5-89b2-1bcfed3ad569 True
SERVER 4 msdb 1/1/0001 12:00:00 AM 8/15/2018 7:01:53 PM 8/10/2018 7:01:45 PM SERVER f79a0d6b-a96d-4aa5-89b2-1bcfed3ad569 True
I also did a Get-Member on it :
Invoke-Command -ComputerName SERVER -ScriptBlock {[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | Out-Null
$server = New-Object Microsoft.SqlServer.Management.Smo.Server "SERVER"
$server.Databases |
Select @{label="Server";Expression={$_.Parent.name}},
@{Label="DB_ID";Expression={$_.ID}},
@{label="Database Name";Expression={$_.Name}},
LastLogBackupDate,
LastDifferentialBackupDate,
LastBackupDate} | GM
TypeName: Deserialized.Selected.Microsoft.SqlServer.Management.Smo.Database
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
Database Name NoteProperty string Database Name=ApexSQLCrd
DB_ID NoteProperty int DB_ID=5
LastBackupDate NoteProperty datetime LastBackupDate=8/10/2018 7:03:22 PM
LastDifferentialBackupDate NoteProperty datetime LastDifferentialBackupDate=8/15/2018 7:04:04 PM
LastLogBackupDate NoteProperty datetime LastLogBackupDate=8/16/2018 6:46:46 PM
PSComputerName NoteProperty string PSComputerName=SERVER
PSShowComputerName NoteProperty bool PSShowComputerName=True
RunspaceId NoteProperty guid RunspaceId=cb9605b8-7bda-44b5-bdc6-2af23f9a8efc
Server NoteProperty string Server=SERVER