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.
Locked
User avatar
mqh777
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

get-childitem

Post by mqh777 » Fri Nov 02, 2018 8:58 am

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

Re: get-childitem

Post by jvierra » Fri Nov 02, 2018 9:06 am

This line does nothing:

$folderlist | Out-String

User avatar
mqh777
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

Re: get-childitem

Post by mqh777 » Fri Nov 02, 2018 9:07 am

with or without that line it still does not return the list of all folders. It only returns 1 folder.

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

Re: get-childitem

Post by jvierra » Fri Nov 02, 2018 9:08 am

The following is all you need.

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

User avatar
mqh777
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

Re: get-childitem

Post by mqh777 » Fri Nov 02, 2018 9:19 am

that too only returns 1 folder name.

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

Re: get-childitem

Post by jvierra » Fri Nov 02, 2018 9:27 am

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

Be sure "multiline" is true.

User avatar
mqh777
Posts: 237
Joined: Tue Feb 25, 2014 1:01 pm

Re: get-childitem

Post by mqh777 » Fri Nov 02, 2018 9:31 am

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

Re: get-childitem

Post by jvierra » Fri Nov 02, 2018 9:39 am

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.

Locked