gpt4 book ai didi

powershell-2.0 - 使用powershell将文件复制到多台计算机

转载 作者:行者123 更新时间:2023-12-05 08:00:56 24 4
gpt4 key购买 nike

我需要按照以下规范将文件从我的计算机复制到多台计算机。

  1. 我需要提供用户名

  2. 我还需要提供密码

  3. 运行时不应再次提示输入密码重要

我使用了以下代码,但它多次要求输入密码。

 read-host -assecurestring | convertfrom-securestring | out-file e:\SSS\pass.txt
$password=get-content e:\SSS\pass.txt | convertto-securestring
$credential=new-object -typename System.Management.Automation.PSCredential -argumentlist KS\KS012\Administrator, $password

最佳答案

下面的脚本应该提示输入凭据,然后提示询问 txt 文件的位置,该文​​件包含您要部署到的 PC 的行分隔列表。然后它会询问您要复制的文件的位置,然后使用预格式化的 UNC c$ 格式询问目的地。

您可以调整此项以设置 PC 列表、要复制的文件的位置以及硬编码的目标。

Get-Credential domain\usermname
$PC = Read-Host "Location of PC List"
$FileLocation = Read-Host "Enter File Location"
$FileDestination = Read-Host "Enter File Destination"
Get-Content $PC | foreach {Copy-Item $FileLocation -Destination \\$_\c$\$FileDestination}

:)

关于powershell-2.0 - 使用powershell将文件复制到多台计算机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16435977/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com