Win32_Volume Name doesn't match a mount point folder - powershell

We have a server with 20+ mount points. All the mount points are physically working fine, however certain ones are showing a 'Name' of \?\Volume{GUID} in Win32_Volume. In addition, in Disk Management, these same ones aren't showing a path when you right click on them and select Change Drive Letter and Paths. But again, the MP is up and working.
Has anyone ever seen this before? It's only an issue because I use a script to return all the MPs underneath a particular drive letter that uses Win32_Volume and it fails for this drive because they are listed as \?\Volume{GUID} instead of their path like all the others.
For anyone interested, here's the Powershell script:
Get-WMIObject -Class "Win32_Volume" -Filter "DriveType=3 AND (Name LIKE 'X:\\%')" | Select Name, Capacity, Freespace | ConvertTo-XML -As string'

They show up that way if they don't have a drive letter assigned. You could try searching for the label instead if it's the same for x:\ on all servers.

Related

Detect drive letter change and re-assign it (usb drive letter) in Windows 10

every now and then Windows (10) will swap the assigned drive letters of my 2 attached usb type 3 devices. So instead of having J: with a label "keedrive" and V: with a label "secondary", Windows will sometimes swap them, J: becomes "secondary" and V: "keedrive". I'm trying to have a Batch script that will check if the drives letter have changed and if so reset them as they were.
Currently, i have to manually re-assign the letters with Diskpart utility.
I have read about How to run a PowerShell script from a batch file and How do I capture the output into a variable from an external process in PowerShell, trying to get a working script. So far i bogged at the level of getting the output of a PowerShell command into a variable, not knowing how to set the condition for checking the drive letters based on the DeviceID and subsequently re-assign the letters accordingly. Please help. In advance thank you.
Here is the PowerShell commands i came up with
Get-CimInstance -ClassName CIM_StorageVolume | Format-Table -Property DeviceID, DriveLetter, Label | Tee-Object -variable UsBDrvLetters
$Drive = Get-CimInstance -ClassName Win32_Volume -Filter "DeviceID = '<YourDeviceID>'"
$Drive | Set-CimInstance -Property #{DriveLetter ='<DesiredLetter>:'}
First command returns the CimInstance object and the second one pipes it to the set-CimInstance.
More to read about this topic:
https://devblogs.microsoft.com/powershell-community/changing-drive-letters-and-labels-via-powershell/
I finally get the script working, albeit using another property (SerialNumber) of the Win32_Volume Class for the filtering.
$Drive = Get-CimInstance -ClassName Win32_Volume -Filter 'SerialNumber like "6316615927"'
$Drive | Set-CimInstance -Property #{DriveLetter ='G:'}
The filtering also works with the "Label" property.
Im still curious/confused as to why i can't filter with the "DeviceID" property; so i will be very very happy to see a solution for that.
Thank you.

Powershell Offline Files Space (Win32_OfflineFilesDiskSpaceLimit)

I'm trying to write a PowerShell script to get some basic information about offline files on Windows 10 computers, including the cache size limit and amount of space in use. It appears that both of these values are stored properties of the WMI class Win32_OfflineFilesDiskSpaceLimit. As seen here, the properties of this class are:
AutoCacheSizeInMB (appears to be the space in use)
TotalSizeInMB (appears to be the space allotted)
However, when I attempt to run the following, nothing is returned:
Get-WmiObject -Class Win32_OfflineFilesDiskSpaceLimit
I have confirmed that Win32_OfflineFilesCache says Active and Enabled are both true.
If there is a better way to gather this information, I am open to suggestions, but I'm still curious why these properties don't seem to exist.
Note: I'm currently using Measure-Object on the Offline Files location to get the amount of space in use, but I can't get the limit this way.
For anyone looking at this in the future, it appears the solution is that an instance of this class exists as a member of the WMI class Win32_OfflineFilesMachineConfiguration (and perhaps also Win32_OfflineFilesUserConfiguration - not sure on that one).
gwmi win32_offlinefilesmachineconfiguration | select -expand diskspacelimitparams
The values are not what I had expected (the AutoCacheSizeInMB property is empty, and the TotalSizeInMB is significantly larger than the result of gci C:\Windows\CSC -Recurse -Force | Measure Length -Sum), but I can tackle that issue separately.

How to find a file location by file name, and file name only, using get_ciminstance in powershell?

I'm trying to write a script that will retrieve a specific file's properties across multiple computers. I was using get-childitem to do this until I realized that only retrieves locally. I've read that get-ciminstance can be used to do this for remote machines, however, all the examples I've seen use full paths to find the files. My script assumes the location could be anywhere on the C drive, so it only looks for the location based on the file's name. So far I've tried several variations of code using get-ciminstance, but all either produce nothing or have the wrong query structure.
Here's what I have right now, and it's what I believe is the closest to being correct, but I'm not sure:
Get-CimInstance -ComputerName $PC -ClassName CIM_DataFile | select Name | Where-Object { $_.Name -like "install.properties"}
If anyone can point me in the right direction, it would be greatly appreciated. Thank you.
Here's a nice link. https://community.idera.com/database-tools/powershell/powertips/b/tips/posts/accessing-individual-files-and-folders-remotely-via-wmi Name is the full path, with double backslashes. The filter language is like sql. You can't use invoke-command?
Get-CimInstance CIM_DataFile -Filter 'name = "c:\\users\\admin\\foo\\file.json"'

Need to scan all domain computers for .pst files

I am new to powershell sctipting, like Brand new. I have some experience using Exchange powershell but thats always been for very specific items like adjust calendar permissions and such. Nothing to robust.
Currently I am working on a powershell script to push out via Group policy that will run a a search on each domain PC. I've been getting help from a co-worker but he isn't available right now and I have a hard time following him sometimes. I am this site and its user might be able to assist me. What I am trying to do(and I believe I am close to) is pulling a list of drives for each computer on the domain. Once I pull that list O pipe it into a variable and then do a search on that variable for any files that end with .pst. Once the search is complete if there were results from the search a file should be created with the FUllname"path" of each file and the computer name should be used for naming the file. If there are no results form the search the file would be empty but the filename should still be named after t he computer. I believe I have gotten everything correct except that I do not know how to name the file based on the computer name. Thank you for your time and help with this.
Here is my code so far:
$drives=Get-WmiObject -query "SELECT * from win32_logicaldisk where
DriveType = '3'" | select deviceid
foreach ($drive in $drives){
$pstfound=Get-ChildItem $drive.deviceid *.pst -recurse | select
fullname
$pst+=$pstfound
}
IF ($pst -eq $null) {
$pst | Out-File \\"Servername"\Searchresults\Null
} Else {
$pst | Out-File \\"Servername"\Searchresults\HasItems
}
Thank you. I wasn't initially planning on using the UNC path but changed it up anyways and I think that will make it easier to go through later. I also figured out my issue for naming the file generated after the computer it ran on. I just set a variable $hostname=hostname and then set the files as \$hostname.csv

Getting all virtual directories for a IIS6 web site using WMI

I want to list all virtual directories that belong to a web site with a certain name using WMI and PowerShell.
I know I can list all virtual directories on a server using the code below, but how can I filter out only those that belong to a specific site?
Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2"
Well, taking the simplest approach here and filtering based on the properties returned from your given example, I would probably opt to use the site identifier portion in the Name property:
Get-WmiObject IIsWebVirtualDir -namespace "ROOT\MicrosoftIISv2" | `
Where-Object { $_.name -like "W3SVC/1/*" }
The above example only shows virtual directories on the default website that is set up with IIS first install. This always has the identifier 1.
Note: the backtick ` after the bar is the line continuation character (actually it's the escape character, but I'm escaping the EOL,) like _ in Visual Basic. I'm using this so the ugly horizontal scrollbars don't show up in the code block above.
-Oisin