#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
Showing posts with label servers. Show all posts
Showing posts with label servers. Show all posts
Wednesday, February 3, 2016
Powershell: RDP log user account off of all servers using jobs.
Monday, October 13, 2014
Powershell: Find all shares on domain using Jobs
Purpose: This script will search AD for all servers and report any shares(includes printers)
This script will do 50 servers at a time
Requires RSAT tools powershell
cls #Find Shares on all Domain computers 50 at a time #www.tonyunger.com cls import-module activedirectory #$Global:Servers = Get-Content "C:\temp\computers.txt" $Global:Servers = Get-ADComputer -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | Select -expand Name $Global:ReportPath = "C:\temp\Shares.txt" $scriptblock = { param($server) $pingResult = Test-Connection -count 1 -ErrorAction SilentlyContinue $server | select IPV4Address $Shares = Get-WmiObject Win32_Share -ComputerName $Server | select name $values = @() if($Error){ if( $Error -like "*Access is denied*"){ return ($server+",AccessDenied") } $Error.Clear() return ($server+",") } foreach ($Share in $shares) { $values += ($Server + "," + $Share) } return $values } function getdata{ $jobs = Get-Job | ? { $_.State -eq "Completed" } foreach( $job in $jobs){ $results = Receive-Job $job Add-Content $ReportPath $results Remove-Job $job } } Add-Content $ReportPath "Server,share" foreach($server in $Servers){ while( (Get-Job).count -ge 50 ){ sleep -Seconds 1 getdata } Start-Job -ScriptBlock $scriptblock -ArgumentList $server } while( (get-job).count -ne 0 ){ sleep -Seconds 1 getdata }
Subscribe to:
Posts (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...