Page 1 of 1

trim string or select file

Posted: Fri Jan 29, 2016 1:50 pm
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"
		
	}
}

Re: trim string or select file

Posted: Fri Jan 29, 2016 5:36 pm
by jvierra
\\10.60.216.30\Backups$\cnu14171bg

SERVER - SHARE - FOLDER

$server,$share,$folders=('\\10.60.216.30\Backups$\cnu14171bg').Split('\',[StringSplitOptions]::RemoveEmptyEntries)

Re: trim string or select file

Posted: Mon Feb 01, 2016 7:27 am
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

Re: trim string or select file

Posted: Mon Feb 01, 2016 7:37 am
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?

Re: trim string or select file

Posted: Mon Feb 01, 2016 7:39 am
by jvierra
What is in the variable?

Re: trim string or select file

Posted: Mon Feb 01, 2016 7:40 am
by tirwin@iot.in.gov
Disregard I had a type O. Your code works great Thank you