Powershell – How to split parent path of a unc path by using powershell powershell Here is a UNC path I've got.\\sharespace\test1\10.0.1212.1 Can I get its parent path\\sharespace\test1\? Best Answer There are a few options. If you have access to the share then: (Get-Item '\\sharespace\test1\10.0.1212.1').Parent.Fullname If you do not have access to the share, you can go the more unpalatable route of manipulating the string in various ways. This is one: $path = '\\sharespace\test1\10.0.1212.1' [string]::Join('\', $path.Split('\')[0..$($path.Split('\').Length-2)]) Related SolutionsPowershell – how to use powershell to get childitem of the parent folder and pick up the latest update child folder This example assumes that by "latest update child folder" you want to use the LastWriteTime attribute. Get-ChildItem "10.*" | Sort-Object -Property LastWriteTime -Descending | Select-Object -First 1 Powershell – Why can’t I get the size of network shared folder? by powershell This looks like exactly what you need: Scripting Guy article on getting folder size I think it's important to note that powershell can typically handle UNC paths natively, so there's no need to map a drive. You should be able to do something like this: $fsobuild = new-Object -com Scripting.FileSystemObject "{0:N2}" -f (($fsobuild.GetFolder($lastbuild.Fullname).Size) / 1MB) + " MB" Related TopicPowershell – Export Firewall Rules using PowerShell that include Program PathPowershell split-path formattingWindows – How to get the log path of Tomcat, using PowerShell
Best Answer
There are a few options. If you have access to the share then:
If you do not have access to the share, you can go the more unpalatable route of manipulating the string in various ways. This is one: