cls #################### #By Tony Unger #Purpose: inventory all services and user accounts running them with jobs # ## $myCol = @() $i =0 $servers = get-adcomputer -filter * | select -expand name $scriptblock = { param([string]$server) get-wmiobject win32_service -computername $Server | select * } $ServersCount = $Servers.count foreach($server in $Servers){ $i++ $running = @(Get-Job | Where-Object { $_.State -eq 'Running' }) Write-Progress -Activity "Gathering computer info" -status "Currently on $server -- $i of $ServersCount" -percentComplete ($i / $ServersCount*100) if ($running.Count -le 50) { Start-Job -ScriptBlock $scriptblock -Name $server -ArgumentList $server, $creds } else { $running | Wait-Job } } while ($running.Count -ge 1) { sleep 1 $running = @(Get-Job | Where-Object { $_.State -eq 'Running' }) } foreach ($job in Get-Job ){ $recjobs = Receive-Job -Keep -Job $job foreach ($recjob in $recjobs){ $Detail = New-Object PSObject $Detail | Add-Member Noteproperty Caption $recjob.Caption $Detail | Add-Member Noteproperty Name $recjob.name $Detail | Add-Member Noteproperty Startname $recjob.startname $Detail | Add-Member Noteproperty Server $recjob.__SERVER $myCol += $Detail } }
These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Showing posts with label all. Show all posts
Showing posts with label all. Show all posts
Monday, April 18, 2016
Powershell: Get services and accounts used to run them on all computers using Jobs
Wednesday, February 3, 2016
Powershell: RDP log user account off of all servers using jobs.
#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 }
Thursday, July 9, 2015
Powershell: Jobs - Search for shares in ad windows servers
Job script to search for shares in a active directory environment.
Update $Domain to your domain and run
#Tony Unger #Tonyunger.com #Scans all AD servers for Shares #50 servers at a time #Will Prompt for creds $i =0 import-module activedirectory cls $creds = Get-Credential $myCol = @() $Domain = "microsoft.com" $Servers = Get-ADComputer -server $Domain -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | Select -expand Name $scriptblock = { param( [string]$server, $creds ) Get-WmiObject Win32_Share -ComputerName $server -Credential $Creds | select * } foreach($server in $Servers){ $i++ $running = @(Get-Job | Where-Object { $_.State -eq 'Running' }) Write-Progress -Activity "Gathering computer info" -status "Currently on $server -- $i of $Servers.count" -percentComplete ($i / $Servers.count*100) if ($running.Count -le 50) { Start-Job -ScriptBlock $scriptblock -Name $server -ArgumentList $server, $creds } else { $running | Wait-Job } } while ($running.Count -ge 1) { sleep 1 $running = @(Get-Job | Where-Object { $_.State -eq 'Running' }) } foreach ($job in Get-Job ){ $recjobs = Receive-Job -Keep -Job $job foreach ($recjob in $recjobs){ $Detail = New-Object PSObject $Detail | Add-Member Noteproperty Name $recjob.name $Detail | Add-Member Noteproperty Path $recjob.path $Detail | Add-Member Noteproperty Server $recjob.__SERVER $myCol += $Detail } } $myCol $myCol | export-csv -Path c:\TEMp\shares\output.csv -notype
Saturday, August 23, 2014
Powershell - get all host files on domain.
Purpose: This script will search AD for Window computers and attempted to connect to each one. Then it will read the contents of the host file and write them to a csv file.
Note: This will take a while to run unless someone wants to make it multithreaded.
I just wrote this so there may need to be some bug fixes but in general it seemed to work.
#Read all host files and write to CSV file Import-Module ActiveDirectory $PATH = "c:\temp\hostfiles.csv" $myCol = @() $AllComputers = Get-ADComputer -Filter {OperatingSystem -Like "Windows*"} -Property * | Select -Expand Name foreach ($Computer in $AllComputers){ $i++ Write-Progress -activity "Scanning Machine $Computer " -status "Scanned: $i of $($AllComputers.Count)" -percentComplete (($i / $AllComputers.Count) * 100) Get-Content -Path "\\$Computer\c$\windows\system32\drivers\etc\hosts" | where {!$_.StartsWith("#")} | foreach { if ($_ -ne ""){ $data = $_ -split " ",2 $Hosts = New-Object -TypeName PSObject -Property @{ Host = $Computer IPAddress = $data[0].Trim() Node = $data[1].Trim() } } $myCol += $Hosts } $myCol |Select Host,Node,IPAddress| Export-Csv -Path $PATH -NoTypeInformation }
Thursday, February 13, 2014
Powershell: Get All AD Group Members
Purpose: This script requires the RSAT tools to work. It connects to AD and gets all groups and users within each group and outputs to a csv file. It can also get single groups and display/exports the results.
################################### #Tony Unger - Get Group members #12/12/2013 #1.0 ################################### Import-Module activedirectory do { cls $response = "N" $ExportPath = "c:\temp\AD_GroupMemberofQuery.csv" $myCol = @() [int]$xMenuChoiceA = 0 while ( $xMenuChoiceA -lt 1 -or $xMenuChoiceA -gt 4 ){ Write-host "Active Directory Group Member Reporting" -foregroundcolor "magenta" Write-host "1. Specifiy a Group" Write-host "2. All Groups" Write-host "3. Quit and exit" [Int]$xMenuChoiceA = read-host "Please enter an option 1 to 3..." } Switch( $xMenuChoiceA ){ 1{$ADGroups = read-host "Please enter the AD group name:"} 2{$ADGroups = Get-ADGroup -filter {GroupCategory -eq "Security" -and GroupScope -eq "Global"} | Select -expand SamAccountName} 3{exit} default{exit} } $i = 0 foreach ($ADGroup in $ADGroups){ $i++ Write-Progress -Activity "Gathering members" -status "Currently on group $ADGroup" -percentComplete ($i / $ADGroups.count*100) $Members = get-adgroupmember $ADGroup -recursive foreach ($MemberofGroup in $Members){ $Detail = New-Object PSObject $Detail | Add-Member Noteproperty GroupName $ADGroup $Detail | Add-Member Noteproperty User $MemberofGroup.Name $Detail | Add-Member Noteproperty Account_Name $MemberofGroup.SamAccountName $myCol += $Detail } } $myCol | Export-Csv -Path $ExportPath -notype Write-Host "File exported to: $ExportPath" [int]$xMenuChoiceB = 0 while ( $xMenuChoiceB -lt 1 -or $xMenuChoiceA -gt 4 ){ cls Write-host "Active Directory Group Member Reporting" -foregroundcolor "magenta" Write-host "1. Display current results" Write-host "2. Query another group" Write-host "3. Quit and exit" [Int]$xMenuChoiceB = read-host "Please enter an option 1 to 3..." } Switch( $xMenuChoiceB ){ 1{$myCol} 2{$response = "Y"} 3{exit} default{exit} } } while ($response -eq "Y")
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...