These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Monday, May 9, 2016
Vmware: Powershell List all Datastores and virtual machines within
Purpose: Need to know if i had any empty datastores attached to my ESXi hosts. Came up with this one liner which will list out all datastores and the vms that are within empty or not.
get-datastore | select name, @{name="VM";e={get-datastore $_.name | get-vm } } | fl
Thursday, May 5, 2016
VMware: Powershell Query each ESX Hosts Syslog
This query will report each host and its current Syslog
get-vmhost | select Name,@{Name="SysLog"; Expression={(get-vmhostsyslogserver $_.name)}} | FL
Monday, April 18, 2016
Powershell: Get services and accounts used to run them on all computers using Jobs
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
}
}
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, December 24, 2015
Powershell: VMware one liner to list total vm that are powered on each host
This one liner will query each host and id its cluster total vms and how many VMs are powered on
Get-VMHost | Select @{N="Cluster";E={Get-Cluster -VMHost $_}}, Name, @{N="Total_VMs";E={($_ | Get-VM).Count}},@{N="Powered_On";E={($_ | get-vm | ? {$_.powerstate -like "*ON*"}).count}} | Sort Cluster, Name | fl
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
Friday, June 5, 2015
Windows: Multiple users, one user gets a blue flash while attempting to launch applications while the other user works fine
I came across an interesting issue where if more then one user is on a Win 2012 r2 server there would be a blue flash while one of the users attempted to launch an application. While the other user would work just fine launching applications. If the user that was working fine logged off the user that was previously not working then would be able to launch applications.
In the event log i saw something similar to this:
Faulting application name: explorer.exe, version: 6.3.9600.17667, time stamp: 0x54c6f7c2
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x0000000000000000
Faulting process id: 0xdd4
Faulting application path: C:\Windows\explorer.exe
Faulting module path: unknown
Faulting package full name:
Faulting package-relative application ID:
Well it turns out Winzip 19+ was installed on the server and seems to have been the root cause of the issue. I found the fix to be disabling Explorer File Association Helper in Winzip Options
In the event log i saw something similar to this:
Faulting application name: explorer.exe, version: 6.3.9600.17667, time stamp: 0x54c6f7c2
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc0000005
Fault offset: 0x0000000000000000
Faulting process id: 0xdd4
Faulting application path: C:\Windows\explorer.exe
Faulting module path: unknown
Faulting package full name:
Faulting package-relative application ID:
Well it turns out Winzip 19+ was installed on the server and seems to have been the root cause of the issue. I found the fix to be disabling Explorer File Association Helper in Winzip Options
Subscribe to:
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 = ...
-
This is a KQL written for Azure Sentinel. Purpose is to search for eventid from Active Directory Domain Services related to Group objects....
