Skip to content

Commit 1ec3a30

Browse files
author
haraldpfirmann
committed
Scripts reviewed
1 parent c5026de commit 1ec3a30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+129
-189
lines changed

DBSystems/SQLServer/Get-DMSSQLAgent.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,19 @@ Param(
4242
[string]$ServerInstance,
4343
[pscredential]$ServerCredential,
4444
[int]$ConnectionTimeout = 30,
45-
[string]$Properties = "Name,State,AgentLogLevel,ErrorLogFile,MaximumHistoryRows,ServiceAccount,ServiceStartMode,SqlAgentAutoStart"
45+
[Validateset('*','Name','State','AgentLogLevel','ErrorLogFile','MaximumHistoryRows','ServiceAccount','ServiceStartMode','SqlAgentAutoStart')]
46+
[string[]]$Properties = @('Name','State','AgentLogLevel','ErrorLogFile','MaximumHistoryRows','ServiceAccount','ServiceStartMode','SqlAgentAutoStart')
4647
)
4748

4849
Import-Module SQLServer
4950

5051
try{
51-
if([System.String]::IsNullOrWhiteSpace($Properties)){
52-
$Properties = '*'
53-
}
5452
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
5553

5654
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
5755
'InputObject' = $instance
5856
}
59-
$result = Get-SqlAgent @cmdArgs | Select-Object $Properties.Split(',')
57+
$result = Get-SqlAgent @cmdArgs | Select-Object $Properties
6058

6159
if($SRXEnv) {
6260
$SRXEnv.ResultMessage = $result

DBSystems/SQLServer/Get-DMSSQLAgentJob.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,20 @@ Param(
4646
[pscredential]$ServerCredential,
4747
[string]$JobName,
4848
[int]$ConnectionTimeout = 30,
49-
[string]$Properties = "Name,State,LastRunDuration,CurrentRunStatus,DateLastModified,Description,EmailLevel,EventLogLevel,OwnerLoginName"
49+
[Validateset('*','Name','State','LastRunDuration','CurrentRunStatus','DateLastModified','Description','EmailLevel','EventLogLevel','OwnerLoginName')]
50+
[string[]]$Properties = @('Name','State','LastRunDuration','CurrentRunStatus','DateLastModified','Description','EmailLevel','EventLogLevel','OwnerLoginName')
5051
)
5152

5253
Import-Module SQLServer
5354

5455
try{
55-
if([System.String]::IsNullOrWhiteSpace($Properties)){
56-
$Properties = '*'
57-
}
5856
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
5957

6058
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'}
6159
if([System.String]::IsNullOrWhiteSpace($JobName) -eq $false){
6260
$cmdArgs.Add('Name',$JobName)
6361
}
64-
$result = Get-SqlAgent -InputObject $instance -ErrorAction Stop | Get-SqlAgentJob @cmdArgs | Select-Object $Properties.Split(',')
62+
$result = Get-SqlAgent -InputObject $instance -ErrorAction Stop | Get-SqlAgentJob @cmdArgs | Select-Object $Properties
6563

6664
if($SRXEnv) {
6765
$SRXEnv.ResultMessage = $result

DBSystems/SQLServer/Get-DMSSQLAgentJobHistory.ps1

-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,6 @@
5555
5656
.Parameter ConnectionTimeout
5757
Specifies the time period to retry the command on the target server
58-
59-
.Parameter Properties
60-
List of properties to expand, comma separated e.g. Name,State. Use * for all properties
6158
#>
6259

6360
[CmdLetBinding()]

DBSystems/SQLServer/Get-DMSSQLAgentJobSchedule.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ Param(
5050
[string]$JobName,
5151
[string]$ScheduleName,
5252
[int]$ConnectionTimeout = 30,
53-
[string]$Properties = "Name,ID,State,ActiveStartDate,ActiveEndDate,DateCreated,FrequencyTypes,IsEnabled,JobCount"
53+
[ValidateSet('*','Name','ID','State','ActiveStartDate','ActiveEndDate','DateCreated','FrequencyTypes','IsEnabled','JobCount')]
54+
[string[]]$Properties = @('Name','ID','State','ActiveStartDate','ActiveEndDate','DateCreated','FrequencyTypes','IsEnabled','JobCount')
5455
)
5556

5657
Import-Module SQLServer
5758

5859
try{
59-
if([System.String]::IsNullOrWhiteSpace($Properties)){
60-
$Properties = '*'
61-
}
6260
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
6361
'ServerInstance' = $ServerInstance
6462
'ConnectionTimeout' = $ConnectionTimeout
@@ -76,7 +74,7 @@ try{
7674
$cmdSchedule.Add('Name',$ScheduleName)
7775
}
7876
$result = Get-SqlAgent @cmdArgs | Get-SqlAgentJob @cmdJob `
79-
| Get-SqlAgentJobSchedule @cmdSchedule | Select-Object $Properties.Split(',')
77+
| Get-SqlAgentJobSchedule @cmdSchedule | Select-Object $Properties
8078

8179
if($SRXEnv) {
8280
$SRXEnv.ResultMessage = $result

DBSystems/SQLServer/Get-DMSSQLAgentJobStep.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,13 @@ Param(
5050
[string]$JobName,
5151
[string]$StepName,
5252
[int]$ConnectionTimeout = 30,
53-
[string]$Properties = "Name,ID,State,Command,LastRunDate,LastRunDuration,LastRunDurationAsTimeSpan,OnFailAction,OnSuccessAction"
53+
[ValidateSet('*','Name','ID','State','Command','LastRunDate','LastRunDuration','LastRunDurationAsTimeSpan','OnFailAction','OnSuccessAction')]
54+
[string[]]$Properties = @('Name','ID','State','Command','LastRunDate','LastRunDuration','LastRunDurationAsTimeSpan','OnFailAction','OnSuccessAction')
5455
)
5556

5657
Import-Module SQLServer
5758

5859
try{
59-
if([System.String]::IsNullOrWhiteSpace($Properties)){
60-
$Properties = '*'
61-
}
6260
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
6361
'ServerInstance' = $ServerInstance
6462
'ConnectionTimeout' = $ConnectionTimeout
@@ -76,7 +74,7 @@ try{
7674
$cmdStep.Add('Name',$StepName)
7775
}
7876
$result = Get-SqlAgent @cmdArgs | Get-SqlAgentJob @cmdJob `
79-
| Get-SqlAgentJobStep @cmdStep | Select-Object $Properties.Split(',')
77+
| Get-SqlAgentJobStep @cmdStep | Select-Object $Properties
8078

8179
if($SRXEnv) {
8280
$SRXEnv.ResultMessage = $result

DBSystems/SQLServer/Get-DMSSQLAgentSchedule.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ Param(
4646
[pscredential]$ServerCredential,
4747
[string]$ScheduleName,
4848
[int]$ConnectionTimeout = 30,
49-
[string]$Properties = "Name,ID,State,ActiveStartDate,ActiveEndDate,DateCreated,FrequencyTypes,IsEnabled,JobCount"
49+
[ValidateSet('*','Name','ID','State','ActiveStartDate','ActiveEndDate','DateCreated','FrequencyTypes','IsEnabled','JobCount')]
50+
[string[]]$Properties = @('Name','ID','State','ActiveStartDate','ActiveEndDate','DateCreated','FrequencyTypes','IsEnabled','JobCount')
5051
)
5152

5253
Import-Module SQLServer
5354

5455
try{
55-
if([System.String]::IsNullOrWhiteSpace($Properties)){
56-
$Properties = '*'
57-
}
5856
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
5957
'ServerInstance' = $ServerInstance
6058
'ConnectionTimeout' = $ConnectionTimeout
@@ -67,7 +65,7 @@ try{
6765
if([System.String]::IsNullOrWhiteSpace($ScheduleName) -eq $false){
6866
$cmdSchedule.Add('Name',$ScheduleName)
6967
}
70-
$result = Get-SqlAgent @cmdArgs | Get-SqlAgentSchedule @cmdSchedule | Select-Object $Properties.Split(',')
68+
$result = Get-SqlAgent @cmdArgs | Get-SqlAgentSchedule @cmdSchedule | Select-Object $Properties
7169

7270
if($SRXEnv) {
7371
$SRXEnv.ResultMessage = $result

DBSystems/SQLServer/Get-DMSSQLBackupHistory.ps1

+5-7
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ Param(
7373
[ValidateSet('Midnight', 'Yesterday', 'LastWeek', 'LastMonth')]
7474
[string]$Since,
7575
[int]$ConnectionTimeout = 30,
76-
[string]$Properties = "Name,Status,Size,SpaceAvailable,Owner,LastBackupDate,LastLogBackupDate,IsUpdateable,DefaultFileGroup,AutoShrink,ActiveConnections"
76+
[ValidateSet('*','Name','Status','Size','SpaceAvailable','Owner','LastBackupDate','LastLogBackupDate','IsUpdateable','DefaultFileGroup','AutoShrink','ActiveConnections')]
77+
[string[]]$Properties = @('Name','Status','Size','SpaceAvailable','Owner','LastBackupDate','LastLogBackupDate','IsUpdateable','DefaultFileGroup','AutoShrink','ActiveConnections')
7778
)
7879

7980
Import-Module SQLServer
8081

8182
try{
82-
if([System.String]::IsNullOrWhiteSpace($Properties)){
83-
$Properties='*'
84-
}
8583
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
8684

8785
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
@@ -106,13 +104,13 @@ try{
106104
$cmdArgs.Add("Since",$Since)
107105
}
108106

109-
$Script:result = Get-SqlBackupHistory @cmdArgs | Select-Object *
107+
$result = Get-SqlBackupHistory @cmdArgs | Select-Object $Properties
110108

111109
if($SRXEnv) {
112-
$SRXEnv.ResultMessage = $Script:result
110+
$SRXEnv.ResultMessage = $result
113111
}
114112
else{
115-
Write-Output $Script:result
113+
Write-Output $result
116114
}
117115
}
118116
catch{

DBSystems/SQLServer/Get-DMSSQLColumnEncryptionKey.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ try{
6363
$cmdArgs.Add("Name",$KeyName)
6464
}
6565

66-
$Script:result = Get-SqlColumnEncryptionKey @cmdArgs | Select-Object *
66+
$result = Get-SqlColumnEncryptionKey @cmdArgs | Select-Object *
6767

6868
if($SRXEnv) {
69-
$SRXEnv.ResultMessage = $Script:result
69+
$SRXEnv.ResultMessage = $result
7070
}
7171
else{
72-
Write-Output $Script:result
72+
Write-Output $result
7373
}
7474
}
7575
catch{

DBSystems/SQLServer/Get-DMSSQLColumnMasterKey.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ try{
6363
$cmdArgs.Add("Name",$KeyName)
6464
}
6565

66-
$Script:result = Get-SqlColumnMasterKey @cmdArgs | Select-Object *
66+
$result = Get-SqlColumnMasterKey @cmdArgs | Select-Object *
6767
if($SRXEnv) {
68-
$SRXEnv.ResultMessage = $Script:result
68+
$SRXEnv.ResultMessage = $result
6969
}
7070
else{
71-
Write-Output $Script:result
71+
Write-Output $result
7272
}
7373
}
7474
catch{

DBSystems/SQLServer/Get-DMSSQLCredential.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@ try{
5656
'Name' = $Name
5757
'Confirm' = $false
5858
}
59-
$Script:result = Get-SqlCredential @cmdArgs | Select-Object *
59+
$result = Get-SqlCredential @cmdArgs | Select-Object *
6060

6161
if($SRXEnv) {
62-
$SRXEnv.ResultMessage = $Script:result
62+
$SRXEnv.ResultMessage = $result
6363
}
6464
else{
65-
Write-Output $Script:result
65+
Write-Output $result
6666
}
6767
}
6868
catch{

DBSystems/SQLServer/Get-DMSSQLDatabase.ps1

+5-7
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ Param(
4646
[pscredential]$ServerCredential,
4747
[string]$DBName,
4848
[int]$ConnectionTimeout = 30,
49-
[string]$Properties = "Name,Status,Size,SpaceAvailable,Owner,LastBackupDate,LastLogBackupDate,IsUpdateable,DefaultFileGroup,AutoShrink,ActiveConnections"
49+
[ValidateSet('*','Name','Status','Size','SpaceAvailable','Owner','LastBackupDate','LastLogBackupDate','IsUpdateable','DefaultFileGroup','AutoShrink','ActiveConnections')]
50+
[string[]]$Properties = @('Name','Status','Size','SpaceAvailable','Owner','LastBackupDate','LastLogBackupDate','IsUpdateable','DefaultFileGroup','AutoShrink','ActiveConnections')
5051
)
5152

5253
Import-Module SQLServer
5354

5455
try{
55-
if([System.String]::IsNullOrWhiteSpace($Properties)){
56-
$Properties='*'
57-
}
5856
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
5957

6058
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
@@ -65,13 +63,13 @@ try{
6563
$cmdArgs.Add("Name",$DBName)
6664
}
6765

68-
$Script:result = Get-SqlDatabase @cmdArgs | Select-Object $Properties.Split(',')
66+
$result = Get-SqlDatabase @cmdArgs | Select-Object $Properties
6967

7068
if($SRXEnv) {
71-
$SRXEnv.ResultMessage = $Script:result
69+
$SRXEnv.ResultMessage = $result
7270
}
7371
else{
74-
Write-Output $Script:result
72+
Write-Output $result
7573
}
7674
}
7775
catch{

DBSystems/SQLServer/Get-DMSSQLErrorLog.ps1

+5-7
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,13 @@ Param(
5959
[ValidateSet('Midnight', 'Yesterday', 'LastWeek','LastMonth')]
6060
[string]$Since,
6161
[int]$ConnectionTimeout = 30,
62-
[string]$Properties = "Date,Source,Text,ServerInstance"
62+
[ValidateSet('*','Date','Source','Text','ServerInstance')]
63+
[string[]]$Properties = @('Date','Source','Text','ServerInstance')
6364
)
6465

6566
Import-Module SQLServer
6667

6768
try{
68-
if([System.String]::IsNullOrWhiteSpace($Properties)){
69-
$Properties='*'
70-
}
7169
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
7270

7371
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
@@ -83,13 +81,13 @@ try{
8381
if((-not $After) -and (-not $Before) -and ([System.String]::IsNullOrWhiteSpace($Since) -eq $false)){
8482
$cmdArgs.Add("Since",$Since)
8583
}
86-
$Script:result = Get-SqlErrorLog @cmdArgs | Select-Object $Properties.Split(',')
84+
$result = Get-SqlErrorLog @cmdArgs | Select-Object $Properties
8785

8886
if($SRXEnv) {
89-
$SRXEnv.ResultMessage = $Script:result
87+
$SRXEnv.ResultMessage = $result
9088
}
9189
else{
92-
Write-Output $Script:result
90+
Write-Output $result
9391
}
9492
}
9593
catch{

DBSystems/SQLServer/Get-DMSSQLInstance.ps1

+6-7
Original file line numberDiff line numberDiff line change
@@ -41,29 +41,28 @@ Param(
4141
[string]$ServerInstance,
4242
[pscredential]$ServerCredential,
4343
[int]$ConnectionTimeout = 30,
44-
[string]$Properties = "DisplayNameOrName,Status,Edition,InstanceName,DomainInstanceName,LoginMode,ServerType,ServiceStartMode,ComputerNamePhysicalNetBIOS"
44+
[Validateset('*','DisplayNameOrName','Status','Edition','InstanceName','DomainInstanceName','LoginMode','ServerType','ServiceStartMode','ComputerNamePhysicalNetBIOS')]
45+
[string[]]$Properties = @('DisplayNameOrName','Status','Edition','InstanceName','DomainInstanceName','LoginMode','ServerType','ServiceStartMode','ComputerNamePhysicalNetBIOS')
4546
)
4647

4748
Import-Module SQLServer
4849

4950
try{
50-
if([System.String]::IsNullOrWhiteSpace($Properties)){
51-
$Properties='*'
52-
}
5351
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
5452
'Confirm' = $false
5553
'ServerInstance' = $ServerInstance
5654
'ConnectionTimeout' = $ConnectionTimeout}
55+
5756
if($null -ne $ServerCredential){
5857
$cmdArgs.Add('Credential',$ServerCredential)
5958
}
60-
$Script:result = Get-SqlInstance @cmdArgs | Select-Object $Properties.Split(',')
59+
$result = Get-SqlInstance @cmdArgs | Select-Object $Properties
6160

6261
if($SRXEnv) {
63-
$SRXEnv.ResultMessage = $Script:result
62+
$SRXEnv.ResultMessage = $result
6463
}
6564
else{
66-
Write-Output $Script:result
65+
Write-Output $result
6766
}
6867
}
6968
catch{

DBSystems/SQLServer/Get-DMSSQLLogin.ps1

+3-5
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,13 @@ Param(
6767
[ValidateSet('All','WindowsUser', 'WindowsGroup', 'SqlLogin', 'Certificate', 'AsymmetricKey', 'ExternalUser', 'ExternalGroup')]
6868
[string]$LoginType = "All",
6969
[int]$ConnectionTimeout = 30,
70-
[string]$Properties = "Name,Status,LoginType,Language,IsLocked,IsDisabled,IsPasswordExpired,MustChangePassword,PasswordExpirationEnabled,HasAccess,State"
70+
[ValidateSet('*','Name','Status','LoginType','Language','IsLocked','IsDisabled','IsPasswordExpired','MustChangePassword','PasswordExpirationEnabled','HasAccess','State')]
71+
[string[]]$Properties = ('Name','Status','LoginType','Language','IsLocked','IsDisabled','IsPasswordExpired','MustChangePassword','PasswordExpirationEnabled','HasAccess','State')
7172
)
7273

7374
Import-Module SQLServer
7475

7576
try{
76-
if([System.String]::IsNullOrWhiteSpace($Properties)){
77-
$Properties='*'
78-
}
7977
$instance = GetSQLServerInstance -ServerInstance $ServerInstance -ServerCredential $ServerCredential -ConnectionTimeout $ConnectionTimeout
8078

8179
[hashtable]$cmdArgs = @{'ErrorAction' = 'Stop'
@@ -99,7 +97,7 @@ try{
9997
$cmdArgs.Add("LoginType",$LoginType)
10098
}
10199
try{
102-
$Script:result = Get-SqlLogin @cmdArgs | Select-Object $Properties.Split(',')
100+
$Script:result = Get-SqlLogin @cmdArgs | Select-Object $Properties
103101
}
104102
catch
105103
{

DBSystems/SQLServer/Invoke-DMSSQLAlwaysOnCommand.ps1

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ try{
7676
Disable-SqlAlwaysOn @cmdArgs
7777
}
7878

79-
$Script:result = Get-SqlInstance $instance | Select-Object $Properties
79+
$result = Get-SqlInstance $instance | Select-Object $Properties
8080
if($SRXEnv) {
81-
$SRXEnv.ResultMessage = $Script:result
81+
$SRXEnv.ResultMessage = $result
8282
}
8383
else{
84-
Write-Output $Script:result
84+
Write-Output $result
8585
}
8686
}
8787
catch{

0 commit comments

Comments
 (0)