PowerShell Basics: Console Configuration | PowerShell content from Windows IT Pro.
Monthly Archives: June 2015
Fix non-visibility of mapped drives for elevated programs
This article explains why this happens and why:
Some Programs Cannot Access Network Locations When UAC Is Enabled.
The above linked article also shows how to work around the issue by a registry modification using regedit. Here is a Powershell command that does the same registry modification. Don’t forget to run Powershell as Administrator.
New-ItemProperty -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System -Name EnableLinkedConnections -Type dword -Value 1
How Can I List Open Sessions and Open Files on a Computer?
I need to update frequently a piece of software on a set of servers. The software is updated just by copying new files into a directory. A piece of cake using Powershell.
The problem is that the directory is shared and users run the software from there – so when I try to copy new version of files over the old one, I’m told that some files are open and cannot be replaced. I need a way to find those open files and close them. I know it can be achieved using Share and Storage Management console – but thats not scriptable.
I searched and found this Ed Wilsons’s post
and this script Jeffrey S. Patton’s mod-posh tools
I took the best bits off them and function looks as this
Function Get-OpenFiles { <# .SYNOPSIS Get a list of files open on the server .DESCRIPTION This function returns a list of files open on a given server. The output is similar to that of the Manage Open Files from the Share and Storage Management console. .PARAMETER ComputerName The NetBIOS or FQDN of the computer .EXAMPLE Get-OpenFiles -ComputerName fs User Path LockCount ---- ---- --------- User1 F:\Users\User1\Documents\Data\... 0 User2 P:\Public 0 #> [CmdletBinding()] Param ( [Parameter(Mandatory=$false, ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true, Position=0)] [Alias("DnsHostName")] [string[]]$ComputerName = $env:COMPUTERNAME ) Begin { } Process { foreach ($c in $ComputerName) { $Server = [adsi]"WinNT://$($c)/LanmanServer" $Resources = $Server.PSBase.Invoke("Resources") foreach ($Resource in $Resources) { Try { $prop = @{User = $Resource.GetType().InvokeMember("User","GetProperty",$null,$Resource,$null) Path = $Resource.GetType().InvokeMember("Path","GetProperty",$null,$Resource,$null) LockCount = $Resource.GetType().InvokeMember("LockCount","GetProperty",$null,$Resource,$null) Computername = $c } $UserResource = New-Object -TypeName PSobject -Property @prop } Catch { #catch exception } #return to output $UserResource } } } End { } } # end of function
I will test it and then add the possibility to close those open files….
Get list of all the junctions present on a disk volume
list of all the junctions present on a disk volume can be obtained by executing dir /aL /s C:\
, where "C:"
is the volume to scan
to create a junctions use mklink
command as described in my other post Hardlinks, Junctions, Symlinks to files or folders
If you prefer Powershell (like me) then notice that since version 5 the commandlets New-Item, Remove-Item, Get-ChildItem
support symbolic links