我正在创建一个菜单,其中一个选项是报告指定文件夹的文件夹大小并将其显示给用户.我输入文件夹名称后
cls
$Path = Read-Host -Prompt 'Please enter the folder name: '
$FolderItems = (Get-ChildItem $Path -recurse | Measure-Object -property length -sum)
$FolderSize = "{0:N2}" -f ($FolderItems.sum / 1MB) + " MB"
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Measure-Object : The property "length" cannot be found in the input for any objects.
At C:\Users\Erik\Desktop\powershell script.ps1:53 char:48
+ ... (Get-ChildItem $Path -recurse | Measure-Object -property length -sum)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException
+ FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.
MeasureObjectCommand
Run Code Online (Sandbox Code Playgroud) 我正在制作一个脚本来设置本地主机上的IP,子网掩码,网关和DNS服务器地址.我有一个工作脚本,但我想确保输入的IP地址是数字字符,并且每个Octet的范围在0-255之间.任何帮助,将不胜感激.
$IP = Read-Host -Prompt 'Please enter the Static IP Address. Format 192.168.x.x'
$MaskBits = 24 # This means subnet mask = 255.255.255.0
$Gateway = Read-Host -Prompt 'Please enter the defaut gateway IP Address. Format 192.168.x.x'
$Dns = Read-Host -Prompt 'Please enter the DNS IP Address. Format 192.168.x.x'
$IPType = "IPv4"
# Retrieve the network adapter that you want to configure
$adapter = Get-NetAdapter | ? {$_.Status -eq "up"}
# Remove any existing IP, gateway from our ipv4 adapter
If …Run Code Online (Sandbox Code Playgroud) powershell ×2