trim string or select file

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 8 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

trim string or select file

Post by tirwin@iot.in.gov »

Sir, I have a FolderBrowserModernDialog which select a path to a file with a computer name. I need the path but I also need to get just the computer name ( which is the name of the folder selected). What property can retrieve the folder selected value/ Or would I have to do some kind of trim on the seleted path?

Where $textPath.Text = \\10.60.216.30\Backups$\cnu14171bg
I also want $selectedFolder.Text = cnu14171bg
$btnBrowse_Click = {
	$folderbrowsermoderndialog1.SelectedPath = $textPath.Text
	if ($folderbrowsermoderndialog1.ShowDialog() -eq 'OK')
	{
		$txtPath.Text = $folderbrowsermoderndialog1.SelectedPath 
		$selectedFolder.Text = $folderbrowsermoderndialog1.
		
		$global:oldComputerObject = Get-ADObject ($oldDistinguishedName)
		$organizationalUnit = Get-ADObject "OU=Agencies, DC=state, DC=in, DC=us"
		
	}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: trim string or select file

Post by jvierra »

\\10.60.216.30\Backups$\cnu14171bg

SERVER - SHARE - FOLDER

$server,$share,$folders=('\\10.60.216.30\Backups$\cnu14171bg').Split('\',[StringSplitOptions]::RemoveEmptyEntries)
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: trim string or select file

Post by tirwin@iot.in.gov »

Thanks for the code and it looks like the code should work but the three varables you suggested are coming back NULL. Even though the variable that I am setting them too is not null but equals the Path \\10.60.216.30\Backups$\cnu14171bg.


$btnBrowse_Click = {
	$folderbrowsermoderndialog1.SelectedPath = $textPath.Text
	if ($folderbrowsermoderndialog1.ShowDialog() -eq 'OK')
	{
		$txtPath.Text = $folderbrowsermoderndialog1.SelectedPath
		$myPath = $folderbrowsermoderndialog1.SelectedPath
		
		$server, $share, $folders = ($myPath).Split('\', [StringSplitOptions]::RemoveEmptyEntrie)
#		$server, $share, $folders = ('\\10.60.216.30\Backups$\cnu14171bg').Split('\', [StringSplitOptions]::RemoveEmptyEntries)
		
		$oldComputerName = $folders
		$oldDistinguishedName = Get-dn computer cn $oldComputerName
		$global:oldComputerObject = Get-ADObject ($oldDistinguishedName)
		$organizationalUnit = Get-ADObject "OU=Agencies, DC=state, DC=in, DC=us"
		
	}
}
Is there something I am missing here?
Where $myPath = \\10.60.216.30\Backups$\cnu14171bg
$server = Null
$share = Null
$Folder = Null
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: trim string or select file

Post by tirwin@iot.in.gov »

Above what I am saying is the string literal works, but when I set it to a variable it does not?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: trim string or select file

Post by jvierra »

What is in the variable?
User avatar
tirwin@iot.in.gov
Posts: 40
Last visit: Tue Mar 14, 2017 9:54 am

Re: trim string or select file

Post by tirwin@iot.in.gov »

Disregard I had a type O. Your code works great Thank you
This topic is 8 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked