Answer the question
In order to leave comments, you need to log in
How to combine powershell script parameters?
Hello!
There is a script that lists all domain PCs except the domain itself
Get-ADComputer -LDAPFilter "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))" -Properties name).name;
1. You also need to add a filter for Windows 10 to the line so that ONLY PCs with windows 10 are displayed. In which part of the code should I insert the fragment to make it work?
(&(objectCategory=computer)(operatingSystem=Windows 10*))
2. check if the PC is on and start the installation, if it is off, then at the end of the installation on online computers, wait until the next PC turns on and continue installation on them:
$computername = (Get -ADComputer -LDAPFilter "(&(objectCategory=computer)(!userAccountControl:1.2.840.113556.1.4.803:=8192))" -Properties name | Sort).name;
Test-Connection -ComputerName $computername;
While ( (Test-Connection -Quiet -Count 1) -eq $False) {
Start-Sleep -Seconds 120
}
If ( (Test-WSMan -ComputerName $computername).wsmid -match "wsmanidentity\.xsd" ) {
# Remoting is enabled
Invoke-Command -Computername $computername -ScriptBlock { powershell "& 'C:\po.exe'" }
}
Else {
Write-Output "Remote PC is off now, waiting...";
}
3. do not re-execute the script on the machines on which it was executed
Invoke-Command -Session $Session -ScriptBlock {
if ((Test-Path "c:\fusion") -eq "True")
{
Write-Output $name " folder present"
Invoke-Command -Computername $computername -ScriptBlock {powershell "& 'C:\po.exe'" }
How to combine everything into 1 heap to make it work?
Thanks to!!!
Answer the question
In order to leave comments, you need to log in
In a good way, you need to get the list of computers once and save it in csv by adding the field-flag "installed"
And then run through the file in search of "not installed" + "available"
For the result, put
Type
1 script - get-adcomputer .. | select name, installed | export-csv -path xxx
2 script
#читаем список всех компов
$all=Import-csv xxx
#проходим по списку в поисках живых где неустановлено
foreach ($comp in $all) {
# проверяем всякие условия
if (-not $comp.installed -and
(test-connection $comp.name) -and
(-not (test-path ....)) { #можно еще условий добавить
#install
Invoke-command -computername $comp.name {
#тут команды установки
# никаких повторных invoke-command и powershell НЕ надо
}
.....
#ставим флаг что установлено
$comp.installed=$true
}
}
#экспортируем обратно в csv с установленными флагами
$all | export-csv xxx
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question