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?
get-childitem
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.
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.
Re: get-childitem
with or without that line it still does not return the list of all folders. It only returns 1 folder.
Re: get-childitem
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
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.
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.