Skip to content

Commit ffd39b2

Browse files
bergmeisterdaxian-dbw
authored andcommitted
PSScriptAnalyzer fixes by category (PowerShell#4261)
- Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'ForEach-Object' (alias is '%' or 'foreach') - Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Where-Object' (alias is '?' or 'where') - Fix PSScriptAnalyzer warnings of type PSAvoidUsingCmdletAliases for 'Select-Object' (alias is 'select') - Fix PSScriptAnalyzer warnings of type PSPossibleIncorrectComparisonWithNull. Essentially, $null has to be on the left-hand side when using it for comparison. - A Test in ParameterBinding.Tests.ps1 needed adapting as this test used to rely on the wrong null comparison - Replace a subset of tests of kind '($object -eq $null) | Should Be $true' with '$object | Should Be $null'
1 parent e23d2e5 commit ffd39b2

99 files changed

Lines changed: 694 additions & 694 deletions

File tree

Some content is hidden

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

build.psm1

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ Fix steps:
291291
log "Run dotnet restore"
292292

293293
$srcProjectDirs = @($Options.Top, "$PSScriptRoot/src/TypeCatalogGen", "$PSScriptRoot/src/ResGen")
294-
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | % { [System.IO.Path]::GetDirectoryName($_) }
294+
$testProjectDirs = Get-ChildItem "$PSScriptRoot/test/*.csproj" -Recurse | ForEach-Object { [System.IO.Path]::GetDirectoryName($_) }
295295

296296
$RestoreArguments = @("--verbosity")
297297
if ($PSCmdlet.MyInvocation.BoundParameters["Verbose"].IsPresent) {
@@ -300,7 +300,7 @@ Fix steps:
300300
$RestoreArguments += "quiet"
301301
}
302302

303-
($srcProjectDirs + $testProjectDirs) | % { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
303+
($srcProjectDirs + $testProjectDirs) | ForEach-Object { Start-NativeExecution { dotnet restore $_ $RestoreArguments } }
304304
}
305305

306306
# handle ResGen
@@ -362,9 +362,9 @@ Fix steps:
362362

363363
# Compile native resources
364364
$currentLocation = Get-Location
365-
@("nativemsh/pwrshplugin") | % {
365+
@("nativemsh/pwrshplugin") | ForEach-Object {
366366
$nativeResourcesFolder = $_
367-
Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | % {
367+
Get-ChildItem $nativeResourcesFolder -Filter "*.mc" | ForEach-Object {
368368
$command = @"
369369
cmd.exe /C cd /d "$currentLocation" "&" "$($vcPath)\vcvarsall.bat" "$NativeHostArch" "&" mc.exe -o -d -c -U "$($_.FullName)" -h "$nativeResourcesFolder" -r "$nativeResourcesFolder"
370370
"@
@@ -402,7 +402,7 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$NativeHostArch" "&
402402

403403
# Copy the binaries from the local build directory to the packaging directory
404404
$dstPath = ($script:Options).Top
405-
$FilesToCopy | % {
405+
$FilesToCopy | ForEach-Object {
406406
$srcPath = Join-Path (Join-Path (Join-Path (Get-Location) "bin") $msbuildConfiguration) "$clrTarget/$_"
407407
log " Copying $srcPath to $dstPath"
408408
Copy-Item $srcPath $dstPath
@@ -468,7 +468,7 @@ cmd.exe /C cd /d "$location" "&" "$($vcPath)\vcvarsall.bat" "$NativeHostArch" "&
468468
# publish netcoreapp2.0 reference assemblies
469469
try {
470470
Push-Location "$PSScriptRoot/src/TypeCatalogGen"
471-
$refAssemblies = Get-Content -Path "powershell.inc" | ? { $_ -like "*microsoft.netcore.app*" } | % { $_.TrimEnd(';') }
471+
$refAssemblies = Get-Content -Path "powershell.inc" | Where-Object { $_ -like "*microsoft.netcore.app*" } | ForEach-Object { $_.TrimEnd(';') }
472472
$refDestFolder = Join-Path -Path $publishPath -ChildPath "ref"
473473

474474
if (Test-Path $refDestFolder -PathType Container) {
@@ -632,7 +632,7 @@ function New-PSOptions {
632632
}
633633

634634
if (-not $Runtime) {
635-
$Runtime = dotnet --info | % {
635+
$Runtime = dotnet --info | ForEach-Object {
636636
if ($_ -match "RID") {
637637
$_ -split "\s+" | Select-Object -Last 1
638638
}
@@ -689,7 +689,7 @@ function Get-PesterTag {
689689
$alltags = @{}
690690
$warnings = @()
691691

692-
get-childitem -Recurse $testbase -File |?{$_.name -match "tests.ps1"}| %{
692+
get-childitem -Recurse $testbase -File | Where-Object {$_.name -match "tests.ps1"}| ForEach-Object {
693693
$fullname = $_.fullname
694694
$tok = $err = $null
695695
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FullName, [ref]$tok,[ref]$err)
@@ -705,7 +705,7 @@ function Get-PesterTag {
705705
$warnings += "TAGS must be static strings, error in ${fullname}, line $lineno"
706706
}
707707
$values = $vAst.FindAll({$args[0] -is "System.Management.Automation.Language.StringConstantExpressionAst"},$true).Value
708-
$values | % {
708+
$values | ForEach-Object {
709709
if (@('REQUIREADMINONWINDOWS', 'SLOW') -contains $_) {
710710
# These are valid tags also, but they are not the priority tags
711711
}
@@ -749,7 +749,7 @@ function Publish-PSTestTools {
749749
$tools = @(
750750
@{Path="${PSScriptRoot}/test/tools/TestExe";Output="testexe"}
751751
)
752-
if ($Options -eq $null)
752+
if ($null -eq $Options)
753753
{
754754
$Options = New-PSOptions
755755
}
@@ -894,7 +894,7 @@ function Start-PSPester {
894894
{
895895
$lines = Get-Content $outputBufferFilePath | Select-Object -Skip $currentLines
896896
$lines | Write-Host
897-
if ($lines | ? { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
897+
if ($lines | Where-Object { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
898898
{
899899
break
900900
}
@@ -1859,7 +1859,7 @@ function Publish-NuGetFeed
18591859
'Microsoft.WSMan.Management',
18601860
'Microsoft.WSMan.Runtime',
18611861
'Microsoft.PowerShell.SDK'
1862-
) | % {
1862+
) | ForEach-Object {
18631863
if ($VersionSuffix) {
18641864
dotnet pack "src/$_" --output $OutputPath --version-suffix $VersionSuffix /p:IncludeSymbols=true
18651865
} else {
@@ -1990,7 +1990,7 @@ function Copy-MappedFiles {
19901990
# Do some intelligence to prevent shooting us in the foot with CL management
19911991

19921992
# finding base-line CL
1993-
$cl = git --git-dir="$PSScriptRoot/.git" tag | % {if ($_ -match 'SD.(\d+)$') {[int]$Matches[1]} } | Sort-Object -Descending | Select-Object -First 1
1993+
$cl = git --git-dir="$PSScriptRoot/.git" tag | ForEach-Object {if ($_ -match 'SD.(\d+)$') {[int]$Matches[1]} } | Sort-Object -Descending | Select-Object -First 1
19941994
if ($cl) {
19951995
log "Current base-line CL is SD:$cl (based on tags)"
19961996
} else {
@@ -2022,7 +2022,7 @@ function Copy-MappedFiles {
20222022
}
20232023

20242024
end {
2025-
$map.GetEnumerator() | % {
2025+
$map.GetEnumerator() | ForEach-Object {
20262026
New-Item -ItemType Directory (Split-Path $_.Value) -ErrorAction SilentlyContinue > $null
20272027
Copy-Item $_.Key $_.Value -Verbose:([bool]$PSBoundParameters['Verbose']) -WhatIf:$WhatIf
20282028
}
@@ -2063,7 +2063,7 @@ function Get-Mappings
20632063

20642064
end {
20652065
$map = @{}
2066-
$mapFiles | % {
2066+
$mapFiles | ForEach-Object {
20672067
$file = $_
20682068
try {
20692069
$rawHashtable = $_ | Get-Content -Raw | ConvertFrom-Json | Convert-PSObjectToHashtable
@@ -2079,7 +2079,7 @@ function Get-Mappings
20792079
$mapRoot = $mapRoot.Replace('\', '/')
20802080
}
20812081

2082-
$rawHashtable.GetEnumerator() | % {
2082+
$rawHashtable.GetEnumerator() | ForEach-Object {
20832083
$newKey = if ($Root) { Join-Path $Root $_.Key } else { $_.Key }
20842084
$newValue = if ($KeepRelativePaths) { ($mapRoot + '/' + $_.Value) } else { Join-Path $mapRoot $_.Value }
20852085
$map[$newKey] = $newValue
@@ -2110,7 +2110,7 @@ function Send-GitDiffToSd {
21102110
$patchPath = (ls (Join-Path (get-command git).Source '..\..') -Recurse -Filter 'patch.exe').FullName
21112111
$m = Get-Mappings -KeepRelativePaths -Root $AdminRoot
21122112
$affectedFiles = git diff --name-only $diffArg1 $diffArg2
2113-
$affectedFiles | % {
2113+
$affectedFiles | ForEach-Object {
21142114
log "Changes in file $_"
21152115
}
21162116

@@ -2227,12 +2227,12 @@ function Convert-TxtResourceToXml
22272227
)
22282228

22292229
process {
2230-
$Path | % {
2231-
Get-ChildItem $_ -Filter "*.txt" | % {
2230+
$Path | ForEach-Object {
2231+
Get-ChildItem $_ -Filter "*.txt" | ForEach-Object {
22322232
$txtFile = $_.FullName
22332233
$resxFile = Join-Path (Split-Path $txtFile) "$($_.BaseName).resx"
22342234
$resourceHashtable = ConvertFrom-StringData (Get-Content -Raw $txtFile)
2235-
$resxContent = $resourceHashtable.GetEnumerator() | % {
2235+
$resxContent = $resourceHashtable.GetEnumerator() | ForEach-Object {
22362236
@'
22372237
<data name="{0}" xml:space="preserve">
22382238
<value>{1}</value>
@@ -2256,7 +2256,7 @@ function Start-XamlGen
22562256
)
22572257

22582258
Use-MSBuild
2259-
Get-ChildItem -Path "$PSScriptRoot/src" -Directory | % {
2259+
Get-ChildItem -Path "$PSScriptRoot/src" -Directory | ForEach-Object {
22602260
$XamlDir = Join-Path -Path $_.FullName -ChildPath Xamls
22612261
if ((Test-Path -Path $XamlDir -PathType Container) -and
22622262
(@(Get-ChildItem -Path "$XamlDir\*.xaml").Count -gt 0)) {
@@ -2274,7 +2274,7 @@ function Start-XamlGen
22742274
throw "No .cs or .g.resources files are generated for $XamlDir, something went wrong. Run 'Start-XamlGen -Verbose' for details."
22752275
}
22762276

2277-
$filesToCopy | % {
2277+
$filesToCopy | ForEach-Object {
22782278
$sourcePath = $_.FullName
22792279
Write-Verbose "Copy generated xaml artifact: $sourcePath -> $DestinationDir"
22802280
Copy-Item -Path $sourcePath -Destination $DestinationDir
@@ -2336,7 +2336,7 @@ function script:ConvertFrom-Xaml {
23362336
log "ConvertFrom-Xaml for $XamlDir"
23372337

23382338
$Pages = ""
2339-
Get-ChildItem -Path "$XamlDir\*.xaml" | % {
2339+
Get-ChildItem -Path "$XamlDir\*.xaml" | ForEach-Object {
23402340
$Page = $Script:XamlProjPage -f $_.FullName
23412341
$Pages += $Page
23422342
}
@@ -2394,7 +2394,7 @@ function script:logerror([string]$message) {
23942394
function script:precheck([string]$command, [string]$missedMessage) {
23952395
$c = Get-Command $command -ErrorAction SilentlyContinue
23962396
if (-not $c) {
2397-
if ($missedMessage -ne $null)
2397+
if ($null -ne $missedMessage)
23982398
{
23992399
Write-Warning $missedMessage
24002400
}

demos/Apache/Apache/Apache.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Function Get-ApacheVHost{
185185
}
186186
}
187187

188-
if ($ServerName -ne $null){
188+
if ($null -ne $ServerName){
189189
$vHost = [ApacheVirtualHost]::New($ServerName, $ConfFile, $ListenAddress.Split(":")[0],$ListenAddress.Split(":")[1])
190190
$ExtProps = GetVHostProps $ConfFile $ServerName $ListenAddress
191191
$vHost.DocumentRoot = $ExtProps.DocumentRoot
@@ -206,7 +206,7 @@ Function Restart-ApacheHTTPServer{
206206
[switch]$Graceful
207207
)
208208

209-
if ($Graceful -eq $null){$Graceful = $false}
209+
if ($null -eq $Graceful){$Graceful = $false}
210210
$cmd = GetApacheCmd
211211
if ($Graceful){
212212
& $global:sudocmd $cmd -k graceful

demos/Apache/apache-demo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Import-Module $PSScriptRoot/Apache/Apache.psm1
22

33
#list Apache Modules
44
Write-Host -Foreground Blue "Get installed Apache Modules like *proxy* and Sort by name"
5-
Get-ApacheModule |Where {$_.ModuleName -like "*proxy*"}|Sort-Object ModuleName | Out-Host
5+
Get-ApacheModule | Where-Object {$_.ModuleName -like "*proxy*"} | Sort-Object ModuleName | Out-Host
66

77
#Graceful restart of Apache
88
Write-host -Foreground Blue "Restart Apache Server gracefully"

demos/Azure/Azure-Demo.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Import-Module AzureRM.NetCore.Preview
1717
Login-AzureRmAccount
1818

1919
### Specify a name for Azure Resource Group
20-
$resourceGroupName = "PSAzDemo" + (New-Guid | % guid) -replace "-",""
20+
$resourceGroupName = "PSAzDemo" + (New-Guid | ForEach-Object guid) -replace "-",""
2121
$resourceGroupName
2222

2323
### Create a new Azure Resource Group
@@ -26,7 +26,7 @@ New-AzureRmResourceGroup -Name $resourceGroupName -Location "West US"
2626
### Deploy an Ubuntu 14.04 VM using Resource Manager cmdlets
2727
### Template is available at
2828
### http://armviz.io/#/?load=https:%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-vm-simple-linux%2Fazuredeploy.json
29-
$dnsLabelPrefix = $resourceGroupName | % tolower
29+
$dnsLabelPrefix = $resourceGroupName | ForEach-Object tolower
3030
$dnsLabelPrefix
3131
$password = ConvertTo-SecureString -String "PowerShellRocks!" -AsPlainText -Force
3232
New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateFile ./Compute-Linux.json -adminUserName psuser -adminPassword $password -dnsLabelPrefix $dnsLabelPrefix
@@ -35,21 +35,21 @@ New-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName -Templa
3535
Get-AzureRmResourceGroupDeployment -ResourceGroupName $resourceGroupName
3636

3737
### Discover the resources we created by the previous deployment
38-
Find-AzureRmResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
38+
Find-AzureRmResource -ResourceGroupName $resourceGroupName | Select-Object Name,ResourceType,Location
3939

4040
### Get the state of the VM we created
4141
### Notice: The VM is in running state
42-
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
42+
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | ForEach-Object properties | ForEach-Object instanceview | ForEach-Object statuses
4343

4444
### Discover the operations we can perform on the compute resource
4545
### Notice: Operations like "Power Off Virtual Machine", "Start Virtual Machine", "Create Snapshot", "Delete Snapshot", "Delete Virtual Machine"
46-
Get-AzureRmProviderOperation -OperationSearchString Microsoft.Compute/* | select OperationName,Operation
46+
Get-AzureRmProviderOperation -OperationSearchString Microsoft.Compute/* | Select-Object OperationName,Operation
4747

4848
### Power Off the Virtual Machine we created
4949
Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Compute/virtualMachines -ResourceName MyUbuntuVM -Action poweroff
5050

5151
### Check the VM state again. It should be stopped now.
52-
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | % properties | % instanceview | % statuses
52+
Get-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName -ODataQuery '$expand=instanceView' | ForEach-Object properties | ForEach-Object instanceview | ForEach-Object statuses
5353

5454
### As you know, you may still be incurring charges even if the VM is in stopped state
5555
### Deallocate the resource to avoid this charge
@@ -59,7 +59,7 @@ Invoke-AzureRmResourceAction -ResourceGroupName $resourceGroupName -ResourceType
5959
Remove-AzureRmResource -ResourceName MyUbuntuVM -ResourceType Microsoft.Compute/virtualMachines -ResourceGroupName $resourceGroupName
6060

6161
### Look at the resources that still exists
62-
Find-AzureRmResource -ResourceGroupName $resourceGroupName | select Name,ResourceType,Location
62+
Find-AzureRmResource -ResourceGroupName $resourceGroupName | Select-Object Name,ResourceType,Location
6363

6464
### Remove the resource group and its resources
6565
Remove-AzureRmResourceGroup -Name $resourceGroupName

demos/SystemD/journalctl-demo.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ Get-SystemDJournal -args "-xe" |Out-Host
66

77
#Drill into SystemD unit messages
88
Write-host -Foreground Blue "Get recent SystemD journal messages for services and return Unit, Message"
9-
Get-SystemDJournal -args "-xe" | Where {$_._SYSTEMD_UNIT -like "*.service"} | Format-Table _SYSTEMD_UNIT, MESSAGE | Select-Object -first 10 | Out-Host
9+
Get-SystemDJournal -args "-xe" | Where-Object {$_._SYSTEMD_UNIT -like "*.service"} | Format-Table _SYSTEMD_UNIT, MESSAGE | Select-Object -first 10 | Out-Host

demos/crontab/CronTab/CronTab.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function Remove-CronJob {
7878
.DESCRIPTION
7979
Removes the exactly matching cron job from the cron table
8080
.EXAMPLE
81-
Get-CronJob | ? {%_.Command -like 'foo *'} | Remove-CronJob
81+
Get-CronJob | Where-Object {%_.Command -like 'foo *'} | Remove-CronJob
8282
.RETURNVALUE
8383
None
8484
.PARAMETER UserName

src/Microsoft.PowerShell.Commands.Management/commands/management/Computer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ public Int16 Delay
19671967
foreach ($computerName in $array[1])
19681968
{
19691969
$ret = $null
1970-
if ($array[0] -eq $null)
1970+
if ($null -eq array[0])
19711971
{
19721972
$ret = Invoke-Command -ComputerName $computerName {$true} -SessionOption (New-PSSessionOption -NoMachineProfile) -ErrorAction SilentlyContinue
19731973
}

src/Microsoft.PowerShell.Commands.Management/commands/management/ControlPanelItemCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public abstract class ControlPanelItemBaseCommand : PSCmdlet
9292
private static readonly string[] s_controlPanelItemFilterList = new string[] { "Folder Options", "Taskbar and Start Menu" };
9393
private const string TestHeadlessServerScript = @"
9494
$result = $false
95-
$serverManagerModule = Get-Module -ListAvailable | ? {$_.Name -eq 'ServerManager'}
95+
$serverManagerModule = Get-Module -ListAvailable | Where-Object {$_.Name -eq 'ServerManager'}
9696
if ($serverManagerModule -ne $null)
9797
{
9898
Import-Module ServerManager

src/Microsoft.PowerShell.Commands.Utility/commands/utility/AddType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,7 @@ private static ConcurrentDictionary<string, string> InitializeStrongNameDictiona
21402140
// $dlls = ((dir c:\windows\Microsoft.NET\Framework\ -fi *.dll -rec) + (dir c:\windows\assembly -fi *.dll -rec)) + (dir C:\Windows\Microsoft.NET\assembly) |
21412141
// % { [Reflection.Assembly]::LoadFrom($_.FullName) }
21422142
// "var strongNames = new ConcurrentDictionary<string, string>(4, $($dlls.Count), StringComparer.OrdinalIgnoreCase);" > c:\temp\strongnames.txt
2143-
// $dlls | Sort-Object -u { $_.GetName().Name} | % { 'strongNames["{0}"] = "{1}";' -f $_.FullName.Split(",", 2)[0], $_.FullName >> c:\temp\strongnames.txt }
2143+
// $dlls | Sort-Object -u { $_.GetName().Name} | ForEach-Object { 'strongNames["{0}"] = "{1}";' -f $_.FullName.Split(",", 2)[0], $_.FullName >> c:\temp\strongnames.txt }
21442144

21452145
// The default concurrent level is 4. We use the default level.
21462146
var strongNames = new ConcurrentDictionary<string, string>(4, 744, StringComparer.OrdinalIgnoreCase);

src/Microsoft.PowerShell.Commands.Utility/commands/utility/ImplicitRemotingCommands.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public sealed class ImportPSSessionCommand : ImplicitRemotingCommandBase
189189
$sourceIdentifier = [system.management.automation.wildcardpattern]::Escape($eventSubscriber.SourceIdentifier)
190190
Unregister-Event -SourceIdentifier $sourceIdentifier -Force -ErrorAction SilentlyContinue
191191
192-
if ($previousScript -ne $null)
192+
if ($null -ne $previousScript)
193193
{
194194
& $previousScript $args
195195
}
@@ -2139,11 +2139,11 @@ function Set-PSImplicitRemotingSession
21392139
[Parameter(Mandatory = $false, Position = 1)]
21402140
[bool] $createdByModule = $false)
21412141
2142-
if ($PSSession -ne $null)
2142+
if ($null -ne $PSSession)
21432143
{{
21442144
$script:PSSession = $PSSession
21452145
2146-
if ($createdByModule -and ($script:PSSession -ne $null))
2146+
if ($createdByModule -and ($null -ne $script:PSSession))
21472147
{{
21482148
$moduleName = Get-PSImplicitRemotingModuleName
21492149
$script:PSSession.Name = '{0}' -f $moduleName
@@ -2184,7 +2184,7 @@ private void GenerateHelperFunctionsSetImplicitRunspace(TextWriter writer)
21842184
private const string HelperFunctionsGetSessionOptionTemplate = @"
21852185
function Get-PSImplicitRemotingSessionOption
21862186
{{
2187-
if ($PSSessionOptionOverride -ne $null)
2187+
if ($null -ne $PSSessionOptionOverride)
21882188
{{
21892189
return $PSSessionOptionOverride
21902190
}}
@@ -2336,22 +2336,22 @@ function Get-PSImplicitRemotingSession
23362336
23372337
$savedImplicitRemotingHash = '{4}'
23382338
2339-
if (($script:PSSession -eq $null) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
2339+
if (($null -eq $script:PSSession) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
23402340
{{
23412341
Set-PSImplicitRemotingSession `
23422342
(& $script:GetPSSession `
23432343
-InstanceId {0} `
23442344
-ErrorAction SilentlyContinue )
23452345
}}
2346-
if (($script:PSSession -ne $null) -and ($script:PSSession.Runspace.RunspaceStateInfo.State -eq 'Disconnected'))
2346+
if (($null -ne $script:PSSession) -and ($script:PSSession.Runspace.RunspaceStateInfo.State -eq 'Disconnected'))
23472347
{{
23482348
# If we are handed a disconnected session, try re-connecting it before creating a new session.
23492349
Set-PSImplicitRemotingSession `
23502350
(& $script:ConnectPSSession `
23512351
-Session $script:PSSession `
23522352
-ErrorAction SilentlyContinue)
23532353
}}
2354-
if (($script:PSSession -eq $null) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
2354+
if (($null -eq $script:PSSession) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
23552355
{{
23562356
Write-PSImplicitRemotingMessage ('{1}' -f $commandName)
23572357
@@ -2370,7 +2370,7 @@ function Get-PSImplicitRemotingSession
23702370
23712371
{8}
23722372
}}
2373-
if (($script:PSSession -eq $null) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
2373+
if (($null -eq $script:PSSession) -or ($script:PSSession.Runspace.RunspaceStateInfo.State -ne 'Opened'))
23742374
{{
23752375
throw '{3}'
23762376
}}

0 commit comments

Comments
 (0)