The below script will provide list of record in each table of the SQL Database.
SELECT DISTINCT t.name AS TableName,
i.rows AS RecordCnt
FROM sysindexes i
INNER JOIN sys.tables t
ON i.id = t.OBJECT_ID
WHERE t.is_ms_shipped = 0
ORDER BY t.name
The below script will provide list of record in each table of the SQL Database.
SELECT DISTINCT t.name AS TableName,
i.rows AS RecordCnt
FROM sysindexes i
INNER JOIN sys.tables t
ON i.id = t.OBJECT_ID
WHERE t.is_ms_shipped = 0
ORDER BY t.name
Some of the useful powershell script which can be used in our day to day life.
1. Get running scheduled tasks on a Windows system.
(get-scheduledtask).where({$_.state -eq \’running\’})
2. Get system uptime from multiple computers
Get-CimInstance Win32_operatingsystem -ComputerName $computers |
Select-Object PSComputername,LastBootUpTime,
@{Name=\”Uptime\”;Expression = {(Get-Date) – $_.LastBootUptime}}
3. Get drive utilization using PSDrives
Get-PSDrive -PSProvider filesystem | where-object {$_.used -gt 0} |
select-Object -property Root,@{name=\”SizeGB\”;expression={($_.used+$_.free)/1GB -as [int]}},
@{name=\”UsedGB\”;expression={($_.used/1GB) -as [int]}},
@{name=\”FreeGB\”;expression={($_.free/1GB) -as [int]}},
@{name=\”PctFree\”;expression={[math]::round(($_.free/($_.used+$_.free))*100,2)}}
4. List of Installed applications
Get-PSDrive -PSProvider filesystem | where-object {$_.used -gt 0} |
select-Object -property Root,@{name=\”SizeGB\”;expression={($_.used+$_.free)/1GB -as [int]}},
@{name=\”UsedGB\”;expression={($_.used/1GB) -as [int]}},
@{name=\”FreeGB\”;expression={($_.free/1GB) -as [int]}},
@{name=\”PctFree\”;expression={[math]::round(($_.free/($_.used+$_.free))*100,2)}}
5. Get details about all external scripts in your %PATH%.
gcm -commandtype externalscript | Get-Item |
Select-Object Directory,Name,Length,CreationTime,LastwriteTime,
@{name=\”Signature\”;Expression={(Get-AuthenticodeSignature $_.fullname).Status }}
6. Get event log utilization for remote computers defined in $computers
gcim Win32_NTEventLogFile -computer $computers -filter \”NumberOfRecords > 0\” |
Select-Object @{Name=\”Computername\”;Expression={$_.CSName}},
LogFileName,
NumberOfRecords,
@{Name=\”Size(KB)\”;Expression={$_.FileSize/1kb}},
@{Name=\”MaxSize(KB)\”;Expression={($_.MaxFileSize/1KB) -as [int]}},
@{name=\”PercentUsed\”;Expression={[math]::round(($_.filesize/$_.maxFileSize)*100,2)}} |
Sort Computername,PercentUsed |
Format-Table -GroupBy Computername -property LogFileName,NumberOfRecords,*Size*,PercentUsed
7. Get freespace for drive C on the local computer formatted in GB
\”$((get-date).ToUniversalTime().tolongdatestring()) UTC\”
Unlock-ADAccount -identity
$SecureString=ConvertTo-SecureString -string Abcd1234 -AsPlainText -Force
Set-ADAccountPassword -Identity TestAccount -Reset -NewPassword $SecureString
20. Remotely restart or shut down another computer
Start-Sleep 60; Restart-Computer –Force –ComputerName TARGETMACHINE
Stop-Computer –computer DC1 –Credential ashish\\administrator