Page 1 of 1

get-childitem

Posted: Fri Nov 02, 2018 8:58 am
by mqh77777
I am trying to get a list of all directories on a server share. In PowerShell ISE it works fine.
$share = "\\server\sharename"
$folderlist = (Get-ChildItem $share -Directory).Name
$folderlist

This will list all folders on the $share.

But when I execute this code in PowerShell Studio it does not get all folders.
$share = "\\server\sharename"
$folderlist = (Get-ChildItem $share -Directory).Name
$folderlist | Out-String
$richtextbox_output.AppendText($folderlist)

It returns the name of 1 folder. Why would it not return all folders on the share?

Re: get-childitem

Posted: Fri Nov 02, 2018 9:06 am
by jvierra
This line does nothing:

$folderlist | Out-String

Re: get-childitem

Posted: Fri Nov 02, 2018 9:07 am
by mqh77777
with or without that line it still does not return the list of all folders. It only returns 1 folder.

Re: get-childitem

Posted: Fri Nov 02, 2018 9:08 am
by jvierra
The following is all you need.

$richtextbox_output.Lines = (Get-ChildItem \\server\sharename -Directory).Name

Re: get-childitem

Posted: Fri Nov 02, 2018 9:19 am
by mqh77777
that too only returns 1 folder name.

Re: get-childitem

Posted: Fri Nov 02, 2018 9:27 am
by jvierra
Works fine for me. Perhaps there is only on folder.

Be sure "multiline" is true.

Re: get-childitem

Posted: Fri Nov 02, 2018 9:31 am
by mqh77777
Here is the entire code for the button on our Form. Yes, the RTB is set to multiline and we have over 200 folders on this share.

Code: Select all

$buttonHasScanstateRun_Click={
	$statusbar1.text = 'Checking to see if scanstate has been run on this machine...'
	$richtextbox_output.Clear()
	$TextPC = $PCNameBox.Text
	$serialnumber = (Get-WmiObject -ComputerName $textPC win32_bios).SerialNumber
	$settingspath = "$OSDServer\files\list.ini"
	$share = $null
	foreach ($gw in get-content $settingspath) {$share = $gw.split("=")[1]	}
	if ($share)
	{
		$share = "\\" + $share
		$folderlist = (Get-ChildItem $share -Directory).Name 
		# $richtextbox_output.Lines = (Get-ChildItem $Share -Directory).Name
		# and since there is no list of folders being shown it always says Scanstate has not run
		foreach ($folder in $FolderList)
		{
		   if ($folder -like "*$serialnumber*")
			{
				$richtextbox_output.SelectionColor = 'Green'
				$richtextbox_output.AppendText("Scanstate has been run on $textpc")
				
				ELSE
				{
					$richtextbox_output.SelectionColor = 'Red'
					$richtextbox_output.AppendText("Scanstate has NOT been run on $textpc.  Please run Scanstate before you run OSD.")
										
				}
			}
		}

	}
}

Re: get-childitem

Posted: Fri Nov 02, 2018 9:39 am
by jvierra
A share takes a computername and a folder name at a minimum.

If you completely change the code and the question I will give up as I don't have time to try to guess at what you are doing.