function - 正确地将参数传递给函数
问题描述
伙计们!今天在我的编码冒险中,我试图创建一个依赖用户输入来设置变量的 powershell 脚本。此脚本的主要目标是能够输入计算机名称和网络位置并远程删除域中指定计算机上的文件。请注意,这确实适用于从文本中获取计算机名称。但是,我想避免创建/编辑 .txt 文件,手动编辑函数中的位置,并从主机输入中提取变量。
问题 1.) 这有可能做到吗?问题 2.) 有人可以查看我的代码并提供建议以正确将参数传递给函数吗?
param (
[string] $Computer = $(Read-Host "Copy Paste Computer name"),
[string] $Location = $(Read-Host "Copy Paste Malicious folder/file location starting with Profile
name")
)
function delete-remotefile {
PROCESS {
$file = "\\$_\c$\$Location"
if (test-path $file)
{
echo "$_ file exists"
Remove-Item $file -force -recurse
echo "$_ file deleted"
}
$file = "\\$_\c$\$Location"
if (test-path $file)
{
echo "$_ file exists"
Remove-Item $file -force -recurse
echo "$_ file deleted"
}
}
}
Get-Content $Location | delete-remotefile
解决方案
推荐阅读
- python - 更改 python 数组形状
- java - 无法在 Kotlin 中使用 Optional 模拟`willReturn`
- android - Android 和 iOS 上的“返回”按钮减少输入类型 =“数字”的值
- python - 将 Cesium 应用程序添加到 Plotly Dash 不起作用
- bash - 删除另一个目录中任意深度的目录
- javascript - 如何获取给定文本的所有像素坐标的数组
- node.js - 如何在nodejs中安排一个时间范围内的cron作业
- python - 根据另一列的值创建具有最大数量索引的新列
- node.js - How to make Mapbox load on gatsby site? Build succeeds but map not displaying, despite working in dev mode
- css - 如何在移动设备上修复图像?