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.
Locked
User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

trim string or select file

Post by tirwin@iot.in.gov » Fri Jan 29, 2016 1:50 pm

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: 13909
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: trim string or select file

Post by jvierra » Fri Jan 29, 2016 5:36 pm

\\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
Joined: Mon Oct 19, 2015 5:45 am

Re: trim string or select file

Post by tirwin@iot.in.gov » Mon Feb 01, 2016 7:27 am

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
Joined: Mon Oct 19, 2015 5:45 am

Re: trim string or select file

Post by tirwin@iot.in.gov » Mon Feb 01, 2016 7:37 am

Above what I am saying is the string literal works, but when I set it to a variable it does not?

jvierra
Posts: 13909
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: trim string or select file

Post by jvierra » Mon Feb 01, 2016 7:39 am

What is in the variable?

User avatar
tirwin@iot.in.gov
Posts: 40
Joined: Mon Oct 19, 2015 5:45 am

Re: trim string or select file

Post by tirwin@iot.in.gov » Mon Feb 01, 2016 7:40 am

Disregard I had a type O. Your code works great Thank you

Locked