Powershell: Extract physical disk properties based on a logical drive name or a filepath [duplicate] - windows

This question already has answers here:
Combine `Get-Disk` info and `LogicalDisk` info in PowerShell?
(3 answers)
obtain disk serial number from drive letter
(4 answers)
Closed 2 years ago.
Went through few similar queries, but could not a get a related solution as per my requirement.
Here is what I want:
I am writing a powershell script that, given a logical drive name (or a filepath), should be able to return me its underlying physical drive info like serial number, manufacturer etc.
I can get these details from Get-Disk or Get-PhysicalDisk. I see logical volume details from Get-Volume. But how do I correlate these two results to filter out results based on a specific logical volume or path (like get serial number of physical disk for the logical drive D:)
Any help is appreciated.
This is what I have tried until now:
My logical driver for which I want to get disk details:
PS C:\Users\Administrator> Get-Volume -FilePath U:\
DriveLetter FriendlyName FileSystemType DriveType HealthStatus OperationalStatus SizeRemaining Size
----------- ------------ -------------- --------- ------------ ----------------- ------------- ----
U New Volume NTFS Fixed Healthy OK 19.91 GB 20 GB
Get-Disk has all the information I need:
PS C:\Users\Administrator> Get-Disk | Select Manufacturer, SerialNumber, UniqueId
Manufacturer SerialNumber UniqueId
------------ ------------ --------
3PARdata SGH622X73L 60002AC0000000000E006A980001AB73
3PARdata SGH622X73L 60002AC0000000000E006A990001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9D0001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9E0001AB73
3PARdata SGH622X73L 60002AC0000000000E006E9F0001AB73
3PARdata SGH622X73L 60002AC0000000000E006EA00001AB73
My problem is, how do I filter out which of the above listing belongs to my logical volume U:\ ?

#zett42's link worked for me. Posting it here again:
get-partition -DriveLetter U | get-disk

Related

Select-Object, different output

I am currently writing a script, that sends me an email, if a new Windows update gets released.
Get-WindowsUpdate
Output:
ComputerName Status KB Size Title ------------ ------ -- ---- -----
MD-I-T-092 ------- 2MB Intel - System - 4/12/2017 12:00:00 AM - 14.28.47.630
MD-I-T-092 ------- 24KB Dell Inc. - Monitor - 1/30/2018 12:00:00 AM -
MD-I-T-092 ------- 46KB Intel - System - 9/19/2017 12:00:00 AM - 11.7.0.1000
MD-I-T-092 ------- 9MB Lenovo Ltd. - Firmware - 1.0.0.50
MD-I-T-092 ------- 346KB Lenovo Ltd. - Firmware - 1.0.0.41
At the moment, only "Driver" updates are available. When a Windows update is available, I want to retrieve the "KB" Number and the "Title" of the update.
Get-WindowsUpdate | Select-Object -Property KB (or Size/Title etc.)
This method doesent work.
Output
I guess that is because the Property is not available.
Get-WindowsUpdate | Select -Property *
All Properties
As this method (https://social.technet.microsoft.com/Forums/en-US/b7e3b522-04b5-4cd5-a228-837deff9d7b8/windows-update-powershell-module-display-category-with-getwindowsupdate-aka-getwulist-cmdlet?forum=ITCG) didnt work for me, do you have any other ideas on how to filter the output?
On StackO I have not found an article that helped me, but if you know one, please let me know :)
I assume you are using the PsWindowsUpdate module.
It seems that module is poorly written and doesn't emit nice useable objects by default.
You can get at them like this:
(Get-WindowsUpdate).GetEnumerator() | Where-Object KB -ne '' | Select-Object KB, Size, Title.
Which gives output like this (assuming matching updates are found):
KB Size Title
-- ---- -----
KB5011644 697MB SQL Server 2019 RTM Cumulative Update (CU) 16 KB5011644
KB5014356 457MB Security Update for SQL Server 2019 RTM GDR (KB5014356)
KB5013887 67MB 2022-06 Cumulative Update for .NET Framework 3.5 and 4.8 for Windows 10 Version 21H2 for x64 (KB5013887)
KB2267602 789MB Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.367.1700.0)
The properties you're looking for aren't available because the Get-WindowsUpdate returns the collection of objects as a whole rather than streaming the elements one by one (like most cmdlets do). In which case, you would have been able to retrieve the individual properties from the objects.
In order to get the information you're looking for, first pipe the Get-WindowsUpdate cmdlet to the ForEach-Object cmdlet and then select your properties from there.
Get-WindowsUpdate | ForEach-Object { $_ | Select Title, KB, Size }
Here's what I get with that:

How to write a powershell script to know disk is basic or dynamic?

I have to check whether a given node contains any dynamic disk or not and get the list of dynamic disk using Power Shell script. I am not supposed to use diskpart command. Any other solutions other than diskpart will be appreciated.
https://social.technet.microsoft.com/Forums/windowsserver/en-US/cd7c0327-3fe9-45fc-a177-5a9927d468f3/does-the-getdisk-funtion-only-return-basic-disks?forum=winserverpowershell
Get-WmiObject Win32_DiskPartition -filter "Type='Logical Disk Manager'" | Select-Object *
you may use also diskpart utility, which is easily scriptable (I worked with it in Python)
the idea is that when you perform diskpart and then list disk,
output will be like:
Disk ### Status Size Free Dyn Gpt
-------- ------------- ------- ------- --- ---
Disk 0 Online 476 GB 0 B *
So you'll see all dynamic disks marked with asterisk under "Dyn"

unlock encrypted external drive from commandline does not work

I'm running 10.13.4 macos.
I created an encrypted hfs usb stick with the password test. After that I unmounted it and removed it from the Macbook. Then I plugged it in again and did NOT enter the password, so that the block devices appear in the device tree.
diskutil cs list delivers
+-- Logical Volume Group FDFF1CAB-A9AC-40E8-8251-FAC5C592296B
=========================================================
Name: Ohne Titel
Status: Online
Size: 3588186112 B (3.6 GB)
Free Space: 14635008 B (14.6 MB)
|
+-< Physical Volume 0DB883F2-4AE3-4D13-AE97-5EF2E4EC28F8
| ----------------------------------------------------
| Index: 0
| Disk: disk4s2
| Status: Online
| Size: 3588186112 B (3.6 GB)
|
+-> Logical Volume Family 1865CD0A-BE9B-490A-8E02-A59498CAB371
----------------------------------------------------------
Encryption Type: AES-XTS
Encryption Status: Locked
Conversion Status: Complete
High Level Queries: Fully Secure
| Passphrase Required
| Accepts New Users
| Has Visible Users
| Has Volume Key
|
+-> Logical Volume 53D7E549-5445-4509-8E0A-2FCB9DC59E4C
---------------------------------------------------
Disk: -none-
Status: Locked
Size (Total): 3221225472 B (3.2 GB)
Revertible: No
LV Name: Ohne Titel
Content Hint: Apple_HFSX
So I tried the following:
diskutil coreStorage unlockVolume 53D7E549-5445-4509-8E0A-2FCB9DC59E4C
Passphrase:
Unable to register passphrase
It asks for the passphrase and I enter the correct one, but I get that error.
diskutil list shows:
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *3.9 GB disk4
1: EFI EFI 209.7 MB disk4s1
2: Apple_CoreStorage Ohne Titel 3.6 GB disk4s2
3: Apple_Boot Boot OS X 134.2 MB disk4s3
so I tried:
sudo hdiutil attach /dev/disk4s2
which then opens the gui where I can type in my password, if I do that it works.
Which is nice but I want a command line only option. Any hints how to do this?
Ok I figured this out I needed to use sudo diskutil coreStorage unlockVolume 53D7E549-5445-4509-8E0A-2FCB9DC59E4C because diskutil seems to silently fail if it is not called with root privileges.

Powershell showing disk space details of inaccessible drives

I tried to retrieve the disk space details of a remote server A from another server B and used the below PowerShell command:
Get-WmiObject -Class Win32_LogicalDisk -ComputerName aa.bb.cc.dd -filter "DriveType=3" | Select DeviceID,#{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},#{Name="FreeSpace(GB)";Expression={"{0:N3}" -f($_.freespace/1gb)}}
The output is as follows:
DeviceID Size(GB) FreeSpace(GB)
-------- -------- -------------
C: 59.9 17.080
D: 20.0 0.875
F: 100.0 81.865
In server A, Drive D is inaccessible. I can't see the drive space details in My computer. I checked the drive space details in Disk Management of server A and found that the above values are correct.
Again I went to server A and ran the following command in its own PowerShell window:
Get-WmiObject -Class Win32_LogicalDisk -filter "DriveType=3" | Select DeviceID,#{Name="Size(GB)";Expression={"{0:N1}" -f($_.size/1gb)}},#{Name="FreeSpace(GB)";Expression={"{0:N3}" -f($_.freespace/1gb)}} | out-file ./local.txt
Now I got the following output:
DeviceID Size(GB) FreeSpace(GB)
-------- -------- -------------
C: 59.9 17.080
D: 0.0 0.000
F: 100.0 81.864
Actually the commands are almost similar. The only difference is that if we try to get the space details of a remote machine, then we need to add the parameter -ComputerName and the remote machine name.
My question is, why is PowerShell showing two different results when I running the command remotely and locally.
The value that it is showing is actually correct.
I've a list of other servers and use this command within a script to find the disk space details of them. Tomorrow, if another drive becomes inaccessible in one of the servers, this command won't help me find it as it would retrieve its details also.

Oracle Database object File backup

How can i take a backup of all database objects(table schema, procedure, function)
and store it in my windows file location every night. I'm connecting using PL/SQL Developer to oracle server located at different location.
To put in short words "I should have backup in my machine rather than the server", Any ideas
Assuming you installed them as part of your Oracle client installation, you could use the Oracle Export and Import utilities to create a logical backup on your client machine.
On the other hand, I would strongly question the wisdom of this requirement. Your DBA ought to be quite concerned about someone generating regular exports of their database that are not under the same controls as the normal backups to prevent them falling into the wrong hands. You're also copying all the data from the database over the network on a regular basis-- that is going to put a substantial load on the database and on the network that are likely to draw the attention of DBAs and network admins.
To back up backup sets from disk to tape:
If you are backing up a subset of available backup sets, then execute the LIST BACKUPSET command to obtain their primary keys.
The following example lists the backup sets in summary form:
RMAN> LIST BACKUPSET SUMMARY;
List of Backups
===============
Key TY LV S Device Type Completion Time #Pieces #Copies Comp Tag
--- -- -- - ----------- --------------- ------- ------- ---- ---
1 B F A DISK 28-MAY-07 1 1 NO TAG20070528T132432
2 B F A DISK 29-MAY-07 1 1 NO TAG20070529T132433
3 B F A DISK 30-MAY-07 1 1 NO TAG20070530T132434
The following example lists details about backup set 3:
RMAN> LIST BACKUPSET 3;
List of Backup Sets
===================
BS Key Type LV Size Device Type Elapsed Time Completion Time
------- ---- -- ---------- ----------- ------------ ---------------
3 Full 8.33M DISK 00:00:01 30-MAY-07
BP Key: 3 Status: AVAILABLE Compressed: NO Tag: TAG20070530T132434
Piece Name: /disk1/oracle/dbs/c-35764265-20070530-02
Control File Included: Ckp SCN: 397221 Ckp time: 30-MAY-07
SPFILE Included: Modification time: 30-MAY-07
SPFILE db_unique_name: PROD

Resources