Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Don';我不知道如何在powershell中将数组转换为字符串_Powershell - Fatal编程技术网

Don';我不知道如何在powershell中将数组转换为字符串

Don';我不知道如何在powershell中将数组转换为字符串,powershell,Powershell,说到powershell,我是个新手 你们能帮我把数组的结果转换成字符串吗? 我的目标是,脚本将检查文件夹大小,如果大小大于或等于声明的值,则将显示文件夹和位置。我很难将结果设置为字符串,以便在监控系统中显示结果 这是剧本 $array= @() $folder = "<enter here the folder location>" Get-ChildItem -Recurse $folder | Where-Object { $_.PSIsContainer

说到powershell,我是个新手

你们能帮我把数组的结果转换成字符串吗? 我的目标是,脚本将检查文件夹大小,如果大小大于或等于声明的值,则将显示文件夹和位置。我很难将结果设置为字符串,以便在监控系统中显示结果

这是剧本

$array= @() 
$folder = "<enter here the folder location>"
Get-ChildItem -Recurse $folder | Where-Object { $_.PSIsContainer } | 
ForEach-Object { 
    $obj = New-Object PSObject  
    $Size = [Math]::Round((Get-ChildItem -Recurse $_.FullName | Measure-Object Length -Sum -ErrorAction SilentlyContinue).sum / 1000MB, 2)
            $obj |Add-Member -MemberType NoteProperty -Name "Path" $_.FullName 
            $obj |Add-Member -MemberType NoteProperty -Name "SizeGB" $Size 
            $obj |Add-Member -MemberType NoteProperty -Name "DateModified" $_.LastWritetime 
                if ($Size -ge  <threshold of foldersize>)
                    {
                    $array +=$obj 
                    }
    } 

 $array
$array=@()
$folder=“”
Get ChildItem-递归$folder | Where对象{$\ PSIsContainer}|
ForEach对象{
$obj=新对象PSObject
$Size=[Math]::四舍五入((Get ChildItem-Recurse$\ FullName | Measure Object Length-Sum-ErrorAction SilentlyContinue)。总和/1000MB,2)
$obj |添加成员-MemberType NoteProperty-Name“Path”$\ux.FullName
$obj |添加成员-成员类型NoteProperty-名称“SizeGB”$Size
$obj |添加成员-成员类型NoteProperty-名称“DateModified”$\u.LastWritetime
如果($Size-ge)
{
$array+=$obj
}
} 
$array

提前感谢您

如果您对默认输出感到满意,只需应用
| Out String
即可将数组作为字符串获取

例如:

$result=$array|输出字符串

如果只想获得一个简单的路径列表,而不需要额外的元数据和头,请尝试以下操作:


$result=$array | Select Object-ExpandProperty Path | Out String

Powershell在显示数组内容方面做得非常好。怎么了?你到底想要什么样的产出?理想情况下,显示当前输出和所需输出。请查看
-f
字符串格式运算符。[grin]文件夹大小脚本已经存在于web上,供您按原样使用或根据需要调整。向我们展示您的监控系统希望显示数据的方式。在不知道这一点的情况下,这个问题是毫无意义的。您好,SBdev,我尝试了您的示例,是的,它确实给了我所需的输出参数。解决方案一直是将$array | out字符串分配给一个变量