function - 无法让它提供正确的输出
问题描述
我有这个功能,但我无法让它工作,$DecimalConversion 输出没有出来。我想我有一些语法错误。
function Get-DecimalNumber(){
$FileCheck = Test-Path "C:\Conversions\conversions.csv"
if($FileCheck){
Do
{
[int]$GetDecimal = Read-host "Write a number between 1-255" | Out-Null
}
while ($GetDecimal -notmatch '\d{1,3}' -or (1..255) -notcontains $GetDecimal)
$DecimalConversion= "{0:X}" -f $GetDecimal
$DecimalConversion
}
else{Write-Warning "Can not find conversions.csv, creating now under C:\Conversions\"; New-Item "C:\Conversions\conversions.csv" -Force | Out-Null}
}
$getfunction=Get-DecimalNumber
解决方案
您可能可以使用更好的while
条件。out-null
但是,您的问题是由于read-host
.
如果您使用它,$GetDecimal
将不会获得您传入的值,因为它out-null
是在分配发生之前处理的。只需将其删除。它应该工作。
推荐阅读
- python - 在 Django 中选中复选框的列表
- azure - 有没有办法在将更改保存到 DevOps GIT 之前查看 Azure 数据工厂中的更改?
- r - 使用 R 的具有高频数据的多协方差矩阵
- hibernate - JPA - 分页,计数(id)很慢
- c# - 在一行上声明多个变量
- c++ - 我在蛇游戏中收到错误代码 -1073741571
- php - 在 Elasticsearch 中使用嵌套文档聚合多个存储桶
- hibernate - 实体未按预期提交(Hibernate ORM with Panache)
- python - 获取名为 region_name 的第三个输入,它是一个字符串。将 region_list 中包含的适当字符串附加到您的打印语句中
- python - 通过 Python 连接到 UCCX 数据库 (Informix)