【问题标题】:How can I get the size of each sub-directory of a remote computer using credentials with powershell?如何使用带有 powershell 的凭据获取远程计算机的每个子目录的大小?
【发布时间】:2026-01-08 18:05:01
【问题描述】:
我希望获取给定计算机和驱动器的所有目录的所有大小。但是,我需要能够包含凭据。
$dirSize = Get-ChildItem $path -recurse -force | select Length |Measure-Object -Sum length
这是我想要做的,但我不能将凭据与 get-childitem 一起使用
【问题讨论】:
标签:
powershell
size
powershell-3.0
filesize
【解决方案1】:
您应该考虑通过 Active Directory 组策略或使用 Enable-PSRemoting(从管理员 PowerShell 提示符)启用 PowerShell 远程处理。您需要在主机和目标系统上启用 PowerShell Remoting。
配置远程处理后,您可以在Invoke-Command PowerShell 命令中使用-Credential 参数指定凭据。
由于此时Get-ChildItem 命令将在本地上下文中(在远程计算机上)运行,因此您无需担心为该特定命令指定其他凭据。