Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
##*********************** ≠≠≠≠ ***********************
## start as ADMIN
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
$testadmin = $currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
if ($testadmin -eq $false) {
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -noexit -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
exit $LASTEXITCODE
}
Write-Host "Данный скрипт перейменует Ваш компьютер. Имя данного ПК - $env:COMPUTERNAME";
start-sleep -m 5000;
##############################################################
function Get-SomeInput {
Write-Host "Имя данного ПК - $env:COMPUTERNAME";
$title = "something"
$question = "Вы хотите его переименовать?"
$choices = "&Да", "&Нет"
$decision = $Host.UI.PromptForChoice($title, $question, $choices, 1)
if ($decision -eq 0) {
Write-Host "Выполняем . . .";
Get-SomeRename
} else {
Write-Host "Отменяем . . ."; break
}
}
function Get-SomeInputNew {
$ASK = "Ввести другое [y/n] или выход"
$Again = "Не правильны выбор!";
$input = read-host ${ASK};
switch ($input) {
"y" {
Get-SomeRename
}
"n" {write-host "Выход"; break}
default {write-host "${Again}";Get-SomeInputNew}
}
}
#########################################
## Rename Computer
function Get-SomeRename {
$nw = Read-Host "Введите новое имя компьютера";
Write-Host "Имя данного ПК: $env:COMPUTERNAME";
Write-Host "Новое имя: $nw";
if ($env:ComputerName -in $nw) {
Write-Host "Новое имя: ${nw} СОВПАДАЕТ с текущим: $env:ComputerName ";
Get-SomeInputNew
} else {
Write-Host "Переименовуем . . ."
Rename-Computer -NewName $nw;
start-sleep -m 3000;
Write-Host "Новое имя компьютера: $nw"
start-sleep -m 3000;
Write-Host "Перезагружаемся"
start-sleep -m 5000;
Restart-Computer -Force -Confirm:$false -Force;
}
}
Get-SomeInput
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment