get-childitem

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 5 years and 4 months 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
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

get-childitem

Post 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?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem

Post by jvierra »

This line does nothing:

$folderlist | Out-String
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: get-childitem

Post by mqh77777 »

with or without that line it still does not return the list of all folders. It only returns 1 folder.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem

Post by jvierra »

The following is all you need.

$richtextbox_output.Lines = (Get-ChildItem \\server\sharename -Directory).Name
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: get-childitem

Post by mqh77777 »

that too only returns 1 folder name.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem

Post by jvierra »

Works fine for me. Perhaps there is only on folder.

Be sure "multiline" is true.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: get-childitem

Post 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.")
										
				}
			}
		}

	}
}
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: get-childitem

Post 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.
This topic is 5 years and 4 months 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