Azure-Samples / Azure-Samples/azure-files-samples
Running .\AzFileDiagnostics.ps1 results in 'Get-WmiObject' is not recognized
- Dominant language
- PowerShell
- Stars
- 261
- Forks
- 202
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 4
Description
I'm trying to troubleshoot a connectivity issue with my fresh Windows 10 Enterprise VM and a fileshare in a storage account in Azure. The VM is also running in azure in the same Vnet and it can for sure properly ping the fileshare, but I'm looking at what is wrong with my permissions....
I am not using the release but instead the latest commit `1f6fdd2bbe07e503e1c5f74142aec149bdecf345`
Anyways, after a while I get this...
```
Do you want to go ahead to map the drive with file share path \\mystorageaccount.file.core.windows.net\audit-done
[Y] Yes [N] No [?] Help (default is "Y"):
Get-WmiObject: "%USERPROFILE$\Downloads\azure-files-samples-master\azure-files-samples-master\AzFileDiagnostics\Windows\AzFileDiagnostics.ps1:1215
Line |
1215 | $Drives = Get-WmiObject -Class Win32_MappedLogicalDisk
| ~~~~~~~~~~~~~
| The term 'Get-WmiObject' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify
| that the path is correct and try again.
```
I spent some time trying to install what ever package I need for `Get-WmiObject`, I've been googling around and most of the docs that I find don't give me the answer I need but instead tell me to use `Get-CimInstance` instead. Also I see that I guess that `Get-CimInstance` is recommended since powershell 3 and I'm using 5.
**I'm hoping you guys could update this or add the specific details on how to get `Get-WmiObject` installed so I can run the troubleshooter.**
Additionally, here are some other 'yak shaving' items I ran into that perhaps some additional docs would help me and others leverage your great tools..
The troubleshooter also needs `AzureRM` as noted in this error I received.
```
======Validating Storage account protocol settings
Please install Azure power shell module using following instructions to proceed further:https://docs.microsoft.com/en-us/powershell/azure/install-az-ps
```
Which, following the links to install `AzureRM` for windows leads me to this note in the documentation...
```
Install a supported version of [PowerShell version 7 or higher](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows)
```
I'm running. ...
```
$PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 1 19041 3803
```
OK, fine. To install powershell 7 ... "Winget is recommended".... but I end up here...
```
winget search Microsoft.PowerShell
winget : The term 'winget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is
correct and try again.
At line:1 char:1
+ winget search Microsoft.PowerShell
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (winget:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
```
Ok, now I need to install `Winget` I go to `https://learn.microsoft.com/en-us/windows/package-manager/winget/` and get that done.
I can install Powershell 7
```
winget install --id Microsoft.Powershell --source winget
>>
Found PowerShell [Microsoft.PowerShell] Version 7.4.0.0
```
I open a new Powershell 7 window as admin `Install-Module -Name Az -Repository PSGallery -Force` works great.
Of course I try running the Troubleshooter now in Powershell 7... resulting in `AzFileDiagnostics.ps1 is not digitally signed` butI can get around that ` Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope CurrentUser`
The rest is trying to login to Azure with the correct subscription, but I got that finally, which landed me at the error message I started with again, this time in powershell 7.
```
\AzFileDiagnostics.ps1:1215
Line |
1215 | $Drives = Get-WmiObject -Class Win32_MappedLogicalDisk
| ~~~~~~~~~~~~~
| The term 'Get-WmiObject' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included,
| verify that the path is correct and try again.
```
Thank you for your time
Contributor guide
Assessment
This issue has not been assessed yet.