Mundy

IT Knowledge Base

User Tools

Site Tools


Sidebar

Contact me at dan@mundy.co for any feedback or suggestions.


My other sites:

Search all my sites:

show_all_mounted_user_profile_disks

Show all Mounted User Profile Disks

Get-WmiObject Win32_Volume -Filter "Label='User Disk'" | ForEach {
    New-Object PSObject -Property @{
        Name = $_.Name
    }
}

Doesn't show the VHDX file though, only the mount points. Still, it's something. eg:

Name


C:\Users\Dan.Mundy
C:\Users\Administrator\

To see all of the available properties: (unfortunately, none show the VHD path)

Get-WmiObject Win32_Volume | fl

Get the SID of the user

(get-aduser c1test1).SID.Value

Get user from SID

$objSID = New-Object System.Security.Principal.SecurityIdentifier `

  ("S-1-5-21-XXXXXXXXX-XXXXXXXXXXXXXXXX")

$objUser = $objSID.Translate( [System.Security.Principal.NTAccount])
$objUser.Value

Check if a file is locked

first example is simpler but I'm not sure I trust it yet:

$file = "E:\UVHD-S-1-5-21-1461015093-2532539850-990275942-1310.vhdx"
try { [IO.File]::OpenWrite($file).close();$true }
catch {$false}

Next example seems solid. Also is easier to understand where to place commands to run if file locked or available.

function checkFileStatus($filePath)
{
    $fileInfo = New-Object System.IO.FileInfo $filePath
 
    try 
    {
        $fileStream = $fileInfo.Open( [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::Read )
        write-host  "[ACTION][FILEAVAILABLE] $filePath is available"
        return $true
    }
    catch
    {
        write-host  "[ACTION][FILELOCKED] $filePath is locked"
        return $false
    }
}
show_all_mounted_user_profile_disks.txt · Last modified: 2018/04/09 09:56 (external edit)