We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 26e6ceb commit 924c6a6Copy full SHA for 924c6a6
1 file changed
Task/Clean up mapped drives.ps1
@@ -9,8 +9,15 @@ param (
9
)
10
11
$networkDrives = Invoke-ImmyCommand -Context "User" {
12
- $result = Get-WmiObject -Query "SELECT * FROM Win32_NetworkConnection"
13
- return $result
+ # Switched from deprecated Get-WmiObject to Get-CimInstance (WS-Man & CIM standard compliant)
+ try {
14
+ $result = Get-CimInstance -ClassName Win32_NetworkConnection -ErrorAction Stop
15
+ return $result
16
+ }
17
+ catch {
18
+ Write-Error "Failed to retrieve network connections via CIM: $_"
19
+ @() # Return empty collection on failure to avoid null reference issues later
20
21
}
22
23
switch($method){
0 commit comments