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 job. Show all posts
Showing posts with label job. 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
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 }
Friday, September 12, 2014
Powershell: get free disk space from computers listed in text file. using Job
Purpose: This script will search a list of computers and report their c drives total and free space into a text file that can be imported into excel.
This is my first time using jobs to speed up the process of gathering the info so there could be a better way of doing this but this seems to work just fine.
cls #Get free disk space code from here. #http://www.codeproject.com/Articles/757946/Retrieve-Disk-Space-of-Remote-Computers-using-Powe $Global:Servers = Get-Content "C:\temp\computers.txt" $Global:ReportPath = "C:\temp\freediskspace.txt" $scriptblock = { param($server) $ConvertToGB = (1024 * 1024 * 1024) $pingResult = Test-Connection -count 1 -ErrorAction SilentlyContinue $server | select IPV4Address $disk = Get-WmiObject Win32_LogicalDisk -ComputerName $Server -Filter "DeviceID='C:'" | Select-Object Size,FreeSpace $values = @() if($Error){ if( $Error -like "*Access is denied*"){ return ($server+",,AccessDenied") } $Error.Clear() return ($server+",,") } $values += ($Server + "," + ($disk.Size / $ConvertToGB) + "," + ($disk.FreeSpace / $ConvertToGB) ) 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,Total,Free" 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 }
Monday, July 2, 2012
Move Sql Agent Jobs to a new server
1. Click on Jobs under SQL Server Agent

2. For 2005 click on the Summary Tab, 2008 Object Explorer Details Tab under View
3. Select the all the jobs you wish to backup listed in the object explorer details tab

4. Right Mouse click and select Script Job As -> Create To -> File
5. Save the sql file to the new server

6. Execute the sql generated script on the new server and the jobs should populate
Credit to BrianBeall94706
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99014

2. For 2005 click on the Summary Tab, 2008 Object Explorer Details Tab under View

3. Select the all the jobs you wish to backup listed in the object explorer details tab

4. Right Mouse click and select Script Job As -> Create To -> File

5. Save the sql file to the new server

6. Execute the sql generated script on the new server and the jobs should populate
Credit to BrianBeall94706
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=99014
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...