我想从计算机名称中检索 IP 地址,但我只想要 IP。
$computer = 'Server1'
$computer = [System.Net.Dns]::GetHostAddresses($computer) | select IPAddressToString
Run Code Online (Sandbox Code Playgroud)
返回@{IPAddressToString=xxxx}。我如何返回“xxxx”
上周我开发了一个脚本来检查是否在指定的机器上启用了 psremoting。本周我开始编写一个可以在指定机器上启用 psremoting 的脚本,但我无法让 psexec 在 powershell 中运行(另外,是的,我知道可以通过组策略启用 psremoting)。这是我的脚本:
$input = Read-Host @"
Select Option
(1)Manually enter computer(s)
(2)Retrieve computer(s) from file
Option
"@
If ($input -eq 1){
$count = Read-Host "How many computers"
$Computers = 1..$count
$b=0;$c=1; ForEach ($Computer in $Computers) {$Computers[$b] = Read-Host "Computer" $c; $b++; $c++}
} ElseIF ($input-eq 2) {
$Computers = Read-Host "File"
$Computers = Get-Content $Computers
} Else {
write-host "Invalid Option"
Exit
}
cls
$User = Read-Host "Enter username"
$Pass = Read-Host "Enter …
Run Code Online (Sandbox Code Playgroud)