Purpose: If you don't want to put a SQL db into single user mode, you can try the following to give yourself permission to a SQL instance.
The following will open a command prompt as the built in security principal "System" using PSExec.
psexec -i -s -d cmd
From there open SQL management studio from within that command prompt.
ie:
c:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
I came up with this independently, but a simple google search will show you others have figured it out as well.
Should be able to now give yourself permissions to log on now depending on how the SQL was initially configured. If this doesn't work you will have to
Start the instance of SQL Server in single-user mode by using either the -m or -f options. Any member of the computer's local Administrators group can then connect to the instance of SQL Server as a member of the sysadmin fixed server role.
http://msdn.microsoft.com/en-us/library/dd207004.aspx
These are just random notes and programs that may have incomplete descriptions. Any scripts or programs use at your risk
Friday, November 21, 2014
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 }
Netapp Busy Lun
Purpose - Find busy lun on a netapp filer running in 7mode
snap list Volume1
Volume Volume1
working...
%/used %/total date name
---------- ---------- ------------ --------
0% ( 0%) 0% ( 0%) Sep 11 16:31 netapp(0135052001)_mirror_computer.336 (snapmirror)
16% (16%) 14% (14%) Sep 09 07:42 sqlsnap__computer_09-09-2012_07.30.29__weekly (busy,LUNs)
lun snap usage -s computer sqlsnap__computer_09-09-2012_07.30.29__weekly
You need to delete the following LUNs before deleting the snapshot
/vol/computer/{dc5a1359-317d-47cd-a408-3dd99ec4059c}.rws
You need to delete the following snapshots before deleting the snapshot
Snapshot - netapp(0135052001)_mirror_computer.336
PowerShell: One liner get distinguishedname for all user accounts in text file
One liner to get users from a text file and create a report of distinguishedname. You need the activedirectory module imported to run.
import-module activedirectory
gc "C:\temp\serviceaccounts.txt" | Foreach-Object {Get-ADUser -filter {CN -like $_} -Properties *} | select Name, SAMAccountName, distinguishedname | export-csv -path c:\temp\test.csv
import-module activedirectory
gc "C:\temp\serviceaccounts.txt" | Foreach-Object {Get-ADUser -filter {CN -like $_} -Properties *} | select Name, SAMAccountName, distinguishedname | export-csv -path c:\temp\test.csv
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 }
Tuesday, August 5, 2014
Powershell: Get list of all services accounts used on Windows servers in domain.
Purpose: This script will search AD for Windows Servers that are enabled and attempted to connect to each server and get a listing of all services and the accounts used to run them.
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.
Requirements: RSAT tools WMI
Import-Module activedirectory cls $ServicesReport = @() $AllServers = Get-ADComputer -Filter {(OperatingSystem -Like "Windows Server*")-and (enabled -eq "true")} -Property SamAccountName | select -expand Name $i = 0 foreach($Server in $AllServers) { $i++ Write-Host "Working on Server: $Server " $i " of " $AllServers.Count try { if (Test-Connection -ComputerName $Server -Quiet) { $Services = Get-WmiObject win32_service -ComputerName $Server | select Name, @{N="StartupType";E={$_.StartMode}}, @{N="ServiceAccount";E={$_.StartName}}, @{N="SystemName";E={$_.Systemname}} foreach ($Service in $Services) { $Detail = New-Object PSObject $Detail | Add-Member Noteproperty ServiceName $($Service.Name) $Detail | Add-Member Noteproperty StartupType $Service.StartupType $Detail | Add-Member Noteproperty ServiceAccount $Service.ServiceAccount $Detail | Add-Member Noteproperty SystemName $Service.Systemname $ServicesReport += $Detail } } } Catch { $Detail = New-Object PSObject $Detail | Add-Member Noteproperty ServiceName "NA" $Detail | Add-Member Noteproperty StartupType "NA" $Detail | Add-Member Noteproperty ServiceAccount "Error" $Detail | Add-Member Noteproperty SystemName $Server $ServicesReport += $Detail } } $ServicesReport | Export-Csv -Path c:\temp\test.csv -NoTypeInformation
Powershell-DellBatchWarrentylookup
Purpose: This script will read serial numbers from a text file then search dells site for warranty information. The get-dellassetinfo function i found from some forum but don't remember where.
################################### $ComputerSerials = gc "c:\temp\SerialNumbers.txt" ################################### Function Get-DellAssetInfo([string]$ServiceTag){ $Asset=New-WebServiceProxy -Uri 'http://xserv.dell.com/services/AssetService.asmx?WSDL' -UseDefaultCredential $Asset.GetAssetInformation([Guid]::NewGuid(),'AssetService',$ServiceTag); } $myCol = @() foreach ($ComputerSerial in $ComputerSerials) { $results=Get-DellAssetInfo $ComputerSerial $SystemType = $results.AssetHeaderData.SystemType $ServiceLevelDescription = $results.Entitlements.ServiceLevelDescription $SystemModel = $results.AssetHeaderData.SystemModel $Region = $results.AssetHeaderData.Region $StartDate = $results.Entitlements.StartDate.Date | Select -ExpandProperty DateTime $EndDate = $results.Entitlements.EndDate.Date | Select -ExpandProperty DateTime Write-Host "Writing $ComputerName info" $x = 0 foreach ($Sdate in $StartDate) { $Detail = New-Object PSObject $Detail | Add-Member Noteproperty ComputerName $ComputerName $Detail | Add-Member Noteproperty Serial $ComputerSerial $Detail | Add-Member Noteproperty Manufacturer $ComputerManufacturer $Detail | Add-Member Noteproperty SystemType $SystemType $Detail | Add-Member Noteproperty SystemModel $SystemModel $Detail | Add-Member Noteproperty Region $Region $Detail | Add-Member Noteproperty ServiceLevelDescription $ServiceLevelDescription.get_Item($x) $Detail | Add-Member Noteproperty StartDate $Sdate $Detail | Add-Member Noteproperty EndDate $EndDate.get_Item($x) $x++ $myCol += $Detail } } $myCol | Export-Csv -Path c:\temp\AD_WarrentyComputerSerialNumbers.csv -notype
Tuesday, July 8, 2014
Vmware vSphere Host Client 6.0
VMware Vsphere 6.0 Host Client 6.0 beta
If you get this error running the Host Client:
uncaught node.js Error Error: EPERM, open 'c:\Program Files\VMware\HostClient\server\logs\VMware_Hostclient_logs.txt'
Run the client as an administrator
uncaught node.js Error Error: EPERM, open 'c:\Program Files\VMware\HostClient\server\logs\VMware_Hostclient_logs.txt'
Run the client as an administrator
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)
-
Running solidcore you may run into a problem where you have to disable it with out using epo or the local CLI Here are the steps. ...
-
List Certificate Templates function get-CertificateTemplates { [ CmdletBinding ()] Param ( [ Parameter ( Mandatory = $True, Va...
-
Wrote this to get certificate expiration information for certificates that expired 5 days ago to ones that expire in 90 days. Wrap an invoke...