#Log User account off all servers
# Tony Unger
#
$Domain = "Microsoft.com"
$Servers = Get-ADComputer -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName -Server $Domain Select -expand Name
$username = read-host "Enter Users Name:"
$i = 0
$scriptblock = {
param(
[string]$server,
$Username
)
$queryResults = (qwinsta /server:$server $Username| foreach { (($_.trim() -replace "\s+",","))} | ConvertFrom-Csv)
foreach ($queryResult in $queryResults){
Logoff /server:$server $queryResult.id
}
}
$TotalServersCount = $Servers.count
foreach($server in $Servers){
$i++
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
Write-Progress -Activity "logging off user" -status "Currently on $server -- $i of $TotalServersCount" -percentComplete ($i / $Servers.count*100)
if ($running.Count -le 50) {
Start-Job -ScriptBlock $scriptblock -Name $server -ArgumentList $server, $username
}
else {
$running | Wait-Job
}
}
while ($running.Count -ge 1) {
sleep 1
$running = @(Get-Job | Where-Object { $_.State -eq 'Running' })
Remove-Job -State Completed
}
These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Wednesday, February 3, 2016
Powershell: RDP log user account off of all servers using jobs.
Subscribe to:
Post Comments (Atom)
Powershell: Microsoft Graph to add new roles to application registration
PowerShell Script Bulk add new roles to application registration in azure. Update $roles with ,Us...
-
Here is an excel document I created that will ping a list of nodes in column A and give results in column B. There are much better tools th...
-
#reads event logs for filter and exports to $Date = ( Get-Date ).AddMinutes(-30) $LogName = 'Security' $ProviderName = ...
-
Using Google Chrome or MS Edge: Disable Javascript post page load. 1. Open console in dev tools 2. press ctrl - alt - p 3. In the run dial...
No comments:
Post a Comment