Mundy

IT Knowledge Base

User Tools

Site Tools


show_all_mounted_user_profile_disks

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
show_all_mounted_user_profile_disks [2017/03/17 13:48]
Dan Mundy created
show_all_mounted_user_profile_disks [2018/04/09 09:56] (current)
Line 19: Line 19:
  
 <​code>​Get-WmiObject Win32_Volume | fl</​code>​ <​code>​Get-WmiObject Win32_Volume | fl</​code>​
 +
 +===== 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:
 +
 +<code powershell>​
 +$file = "​E:​\UVHD-S-1-5-21-1461015093-2532539850-990275942-1310.vhdx"​
 +try { [IO.File]::​OpenWrite($file).close();​$true }
 +catch {$false}
 +</​code>​
 +
 +Next example seems solid. Also is easier to understand where to place commands to run if file locked or available.
 +
 +<code powershell>​
 +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
 +    }
 +}
 +</​code>​
show_all_mounted_user_profile_disks.txt ยท Last modified: 2018/04/09 09:56 (external edit)