$vmhost = Get-Content "C:\Users\users1\Desktop\vm.txt"
If (Test-WSMan -ComputerName $vmhost -Authentication default -ErrorAction Stop)
{
$RS = Enter-PSSession -ComputerName $vmhost
Invoke-Command -Session $RS -ScriptBlock {Stop-VM -Name * -Force}
Start-Sleep -Seconds 300
$RunningVM = Invoke-Command -Session $RS -ScriptBlock {Get-VM | Where{$_.State -eq 'Running'}}
If (!($RunningVM))
{
Invoke-Command -Session $RS -ScriptBlock {stop-computer -force}
}
....
}
Stop-VM -Force
- если на ВМ есть активные сессии, то дается 5 минут на завершение/сохранение работы, после чего ВМ выключается. Если активных сессий нет, то ВМ останавливается сразуПри выполнении скрипта появляется зеленная полоска "[Завершение работы]"- при запуске скрипта в PowerShell ISE увидите зеленую полоску
-properties *- это сильно замедляет работу командлета, особенно, при большой количестве пользователей.
cscript.exe slmgr...
? Вам обязательно все это запихивать в Python? Теперь вывод информации отрабатывает три раза, а имя проверяемого пк спрашивает дваждыпотому что вы добавляете введенное имя компа в набор $ArrComputers, а потом дергаете каждый раз весь $ArrComputers через ForEach, т.е. первый ответ на первый ввод, второй и третий ответы - на второй ввод, т.к. в наборе уже два имени
$ArrComputers = Read-Host("Введите имена компьютеров через запятую")
$computerDrives = Get-WmiObject -Class MSFT_PhysicalDisk -Namespace "root\Microsoft\Windows\Storage" -ComputerName $ArrComputers | Format-Table (или Format-List) prop1,prop2...
$computerOS = get-wmiobject Win32_OperatingSystem -ComputerName $ArrComputers
$Paths = Import-Csv -Path "C:\temp\OldFiles.csv" -Delimiter ';'
$ToMove = "C:\temp\ToMove.csv"
foreach ($Row in $Paths)
{
$Path = $Row.FullName
If ($Path.Substring(0,2) -eq "\\") {$Newpath = ("\\?\D:\11111\To_Move" + $Path.Remove(0,12))}
$Destpath = Split-Path $Newpath -Parent
$Row | Add-Member -NotePropertyName "NewPath" -NotePropertyValue $DestPath
}
$Paths | Export-Csv -Force -Path $ToMove -Encoding UTF8 -Delimiter ";" -NoTypeInformation
$oldfile = Get-ChildItem -Path $OldPath -File -Recurse | Select Name,Length,LastWriteTime
$newfile = Get-ChildItem -Path $NewPath -File -Recurse | Select Name,Length,LastWriteTime
Compare-Object $oldfile $newfile -Property Name,Length,LastWriteTime -PassThru -IncludeEqual |
Where-Object { $_.SideIndicator -eq '<=' } |
Foreach-Object { Copy-Item $_.Path -Destination $Destination }
$computers = Get-Content -Path C:\temp\os_version.csv
Get-WmiObject -ComputerName $computers -Class Win32_UserAccount -Filter "LocalAccount=True" | Select PSComputername, Name, Status, Disabled, AccountType, Lockout, PasswordRequired, PasswordChangeable | Out-GridView
$userDN = (Get-ADUser -Identity username -Properties DistinguishedName).DistinguishedName
$user = [ADSI]"LDAP://$userDN"
# Get Property Value
$user.InvokeGet('ConnectClientDrivesAtLogon')
...
# Set Property Value
$user.InvokeSet('ConnectClientDrivesAtLogon',0)
$user.CommitChanges()
$PathIn = "\\Server\files"
$VHDXSet = Get-ChildItem -Path $PathIn -Filter UVHD-S*.vhdx | select FullName
$DisabledUsers = Get-ADUser -Filter * | Where {$_.Enabled -eq $False} | select SID
Foreach($VHDXFile in $VHDXSet)
{
$FileName = $VHDXFile.FullName
Foreach($User in $DisabledUser)
{
$UserSID = $User.SID.ToString()
If($FileName.Contains($UserSID))
{
Remove-Item -Path $FileName -Confirm:$true
}
}
}