1
- Function Invoke-Ping
1
+ Function Invoke-Ping
2
2
{
3
3
<#
4
4
. SYNOPSIS
@@ -147,12 +147,12 @@ Function Invoke-Ping
147
147
$StandardUserEnv = [powershell ]::Create().addscript({
148
148
149
149
# Get modules and snapins in this clean runspace
150
- $Modules = Get-Module | Select - ExpandProperty Name
151
- $Snapins = Get-PSSnapin | Select - ExpandProperty Name
150
+ $Modules = Get-Module | Select-Object - ExpandProperty Name
151
+ $Snapins = Get-PSSnapin | Select-Object - ExpandProperty Name
152
152
153
153
# Get variables in this clean runspace
154
154
# Called last to get vars like $? into session
155
- $Variables = Get-Variable | Select - ExpandProperty Name
155
+ $Variables = Get-Variable | Select-Object - ExpandProperty Name
156
156
157
157
# Return a hashtable where we can access each.
158
158
@ {
@@ -167,22 +167,22 @@ Function Invoke-Ping
167
167
# Exclude common parameters, bound parameters, and automatic variables
168
168
Function _temp { [cmdletbinding ()]
169
169
param () }
170
- $VariablesToExclude = @ ((Get-Command _temp | Select - ExpandProperty parameters).Keys + $PSBoundParameters.Keys + $StandardUserEnv.Variables )
171
- Write-Verbose " Excluding variables $ ( ($VariablesToExclude | sort ) -join " , " ) "
170
+ $VariablesToExclude = @ ((Get-Command _temp | Select-Object - ExpandProperty parameters).Keys + $PSBoundParameters.Keys + $StandardUserEnv.Variables )
171
+ Write-Verbose " Excluding variables $ ( ($VariablesToExclude | Sort-Object ) -join " , " ) "
172
172
173
173
# we don't use 'Get-Variable -Exclude', because it uses regexps.
174
174
# One of the veriables that we pass is '$?'.
175
175
# There could be other variables with such problems.
176
176
# Scope 2 required if we move to a real module
177
- $UserVariables = @ (Get-Variable | Where { -not ($VariablesToExclude -contains $_.Name ) })
178
- Write-Verbose " Found variables to import: $ ( ($UserVariables | Select - expandproperty Name | Sort) -join " , " | Out-String ) .`n "
177
+ $UserVariables = @ (Get-Variable | Where-Object { -not ($VariablesToExclude -contains $_.Name ) })
178
+ Write-Verbose " Found variables to import: $ ( ($UserVariables | Select-Object - expandproperty Name | Sort-Object ) -join " , " | Out-String ) .`n "
179
179
180
180
}
181
181
182
182
if ($ImportModules )
183
183
{
184
- $UserModules = @ (Get-Module | Where { $StandardUserEnv.Modules -notcontains $_.Name -and (Test-Path $_.Path - ErrorAction SilentlyContinue) } | Select - ExpandProperty Path)
185
- $UserSnapins = @ (Get-PSSnapin | Select - ExpandProperty Name | Where { $StandardUserEnv.Snapins -notcontains $_ })
184
+ $UserModules = @ (Get-Module | Where-Object { $StandardUserEnv.Modules -notcontains $_.Name -and (Test-Path $_.Path - ErrorAction SilentlyContinue) } | Select-Object - ExpandProperty Path)
185
+ $UserSnapins = @ (Get-PSSnapin | Select-Object - ExpandProperty Name | Where-Object { $StandardUserEnv.Snapins -notcontains $_ })
186
186
}
187
187
}
188
188
@@ -220,7 +220,7 @@ Function Invoke-Ping
220
220
$runMin = [math ]::Round($runtime.totalminutes , 2 )
221
221
222
222
# set up log object
223
- $log = " " | select Date, Action, Runtime, Status, Details
223
+ $log = " " | Select-Object Date, Action, Runtime, Status, Details
224
224
$log.Action = " Removing:'$ ( $runspace.object ) '"
225
225
$log.Date = $currentdate
226
226
$log.Runtime = " $runMin minutes"
@@ -295,7 +295,7 @@ Function Invoke-Ping
295
295
296
296
# Clean out unused runspace jobs
297
297
$temphash = $runspaces.clone ()
298
- $temphash | Where { $_.runspace -eq $Null } | ForEach {
298
+ $temphash | Where-Object { $_.runspace -eq $Null } | ForEach-Object {
299
299
$Runspaces.remove ($_ )
300
300
}
301
301
@@ -345,7 +345,7 @@ Function Invoke-Ping
345
345
[void ]$list.Add ($Ast.SubExpression )
346
346
}
347
347
348
- $UsingVar = $UsingVariables | Group Parent | ForEach { $_.Group | Select - First 1 }
348
+ $UsingVar = $UsingVariables | Group-Object Parent | ForEach-Object { $_.Group | Select-Object - First 1 }
349
349
350
350
# Extract the name, value, and create replacements for each
351
351
$UsingVariableData = ForEach ($Var in $UsingVar )
@@ -440,11 +440,11 @@ Function Invoke-Ping
440
440
if ($LogFile )
441
441
{
442
442
New-Item - ItemType file - path $logFile - force | Out-Null
443
- (" " | Select Date, Action, Runtime, Status, Details | ConvertTo-Csv - NoTypeInformation - Delimiter " ;" )[0 ] | Out-File $LogFile
443
+ (" " | Select-Object Date, Action, Runtime, Status, Details | ConvertTo-Csv - NoTypeInformation - Delimiter " ;" )[0 ] | Out-File $LogFile
444
444
}
445
445
446
446
# write initial log entry
447
- $log = " " | Select Date, Action, Runtime, Status, Details
447
+ $log = " " | Select-Object Date, Action, Runtime, Status, Details
448
448
$log.Date = Get-Date
449
449
$log.Action = " Batch processing started"
450
450
$log.Runtime = $null
@@ -557,7 +557,7 @@ Function Invoke-Ping
557
557
# endregion add scripts to runspace pool
558
558
}
559
559
560
- Write-Verbose (" Finish processing the remaining runspace jobs: {0}" -f (@ ($runspaces | Where { $_.Runspace -ne $Null }).Count))
560
+ Write-Verbose (" Finish processing the remaining runspace jobs: {0}" -f (@ ($runspaces | Where-Object { $_.Runspace -ne $Null }).Count))
561
561
Get-RunspaceData - wait
562
562
563
563
if (-not $quiet )
@@ -728,7 +728,7 @@ Function Invoke-Ping
728
728
{
729
729
$DNSEntity = [Net.Dns ]::GetHostEntry($name )
730
730
$domain = ($DNSEntity.hostname ).replace(" $name ." , " " )
731
- $ips = $DNSEntity.AddressList | % {
731
+ $ips = $DNSEntity.AddressList | ForEach-Object {
732
732
if (-not (-not $IPV6 -and $_.AddressFamily -like " InterNetworkV6" ))
733
733
{
734
734
$_.IPAddressToString
@@ -737,7 +737,7 @@ Function Invoke-Ping
737
737
}
738
738
catch
739
739
{
740
- $rst = New-Object - TypeName PSObject - Property $Hash | Select - Property $props
740
+ $rst = New-Object - TypeName PSObject - Property $Hash | Select-Object - Property $props
741
741
$rst.name = $name
742
742
$results += $rst
743
743
$failed = 1
@@ -748,7 +748,7 @@ Function Invoke-Ping
748
748
foreach ($ip in $ips )
749
749
{
750
750
751
- $rst = New-Object - TypeName PSObject - Property $Hash | Select - Property $props
751
+ $rst = New-Object - TypeName PSObject - Property $Hash | Select-Object - Property $props
752
752
$rst.name = $name
753
753
$rst.ip = $ip
754
754
$rst.domain = $domain
@@ -832,7 +832,7 @@ Function Invoke-Ping
832
832
$w = [wmi ] ' '
833
833
$w.psbase.options.timeout = 15000000
834
834
$w.path = " \\$Name \root\cimv2:Win32_ComputerSystem.Name='$Name '"
835
- $w | select none | Out-Null
835
+ $w | Select-Object none | Out-Null
836
836
$rst.RPC = $true
837
837
}
838
838
catch
@@ -897,8 +897,8 @@ Function Invoke-Ping
897
897
$detail = " WSMan" , " RemoteReg" , " RPC" , " RDP" , " SMB"
898
898
}
899
899
900
- $detail | Select - Unique | Foreach-Object { $TestServerParams.add ($_ , $True ) }
901
- Test-Server @TestServerParams | Select - Property $ (" Name" , " IP" , " Domain" , " Ping" + $detail )
900
+ $detail | Select-Object - Unique | Foreach-Object { $TestServerParams.add ($_ , $True ) }
901
+ Test-Server @TestServerParams | Select-Object - Property $ (" Name" , " IP" , " Domain" , " Ping" + $detail )
902
902
}
903
903
Catch
904
904
{
@@ -914,7 +914,7 @@ Function Invoke-Ping
914
914
$result = $null
915
915
if ($result = @ (Test-Connection - ComputerName $computer - Count 2 - erroraction Stop))
916
916
{
917
- $Output = $result | Select - first 1 - Property Address,
917
+ $Output = $result | Select-Object - first 1 - Property Address,
918
918
IPV4Address,
919
919
IPV6Address,
920
920
ResponseTime,
@@ -948,7 +948,7 @@ Function Invoke-Ping
948
948
$status = " Error: $_ "
949
949
}
950
950
951
- " " | Select - Property @ { label = " Address" ; expression = { $computer } },
951
+ " " | Select-Object - Property @ { label = " Address" ; expression = { $computer } },
952
952
IPV4Address,
953
953
IPV6Address,
954
954
ResponseTime,
0 commit comments