1
添付されているスクリプトに、PCに特定のホスト名がある場合、PCの名前を変更しようとしています。しかし、スクリプトはとにかく進み、if/elseステートメントをバイパスします。ホスト名を変数としてif文を作成する際にエラーが発生しました。
私は間違っていますか?私はWindows Powershellの新機能です。
ありがとうございます!二つの値は、あなたが-eq
演算子を使用する必要がPowerShellで等しいかどうかを比較するには
# get current computername
$hostname = hostname.exe
#$env:computername
If ($hostname = "CLNT3100")
{
#Get all the computers with CLNT3* and sort them with the 'highest client' on top. Then put them in newlist.txt
Get-ADComputer -Filter 'SamAccountName -like "CLNT3*"' | Select -Exp Name | Sort-Object -Descending >> C:\newlist.txt
#Put the text file in a variable and show the top line
$Text = Get-Content -Path C:\newlist.txt
#$Text[0]
#Trim CLNT for numbering
$Text1 = $Text[0].TrimStart("CLNT")
#Add 1 number to the previous CLNT
$Text2 = 1 + $Text1
#Add CLNT again to the new variable
$Text3 = "CLNT" + $Text2
#Rename the computer
Rename-Computer –computername minint –newname $Text3
}
Else
{
Write-Host "Computernaam is niet minint!!!"
}
OKですので、If($ hostname -eq "CLNT3100")? – Kevin
はい。これは-eq/-like/-matchとなります。あなたが何をしているかによって。 –