Get-Service -RequiredServices xxx Get-Service | Where-Object {$_.displayname -like "*Web*"} Get-Service | Sort-Object status,displayname Get-Service | Where-Object {$_.status -eq "running"} Get-Service | Where-Object {$_.status -eq "running" -and $_.displayname -like "*Application*"}Get-WmiObject win32_service | Where-Object {$_.displayname -like "SQL Server (MSSQLSERVER)"} | format-list *Get-Process Stop-Process -processname notepad Start-Service btwdins Stop-Service btwdins Restart-Service btwdins,alerter Stop-Computer -Force Stop-Computer -ComputerName "Server01", "Server02", "localhost" Stop-Computer –computer DC1 –Credential nwtraders\administrator Restart-Computer -WhatIf Restart-Computer "server01","server02","server03" Get-EventLog system -newest 5 | Sort-Object eventid -descendingGet-EventLog -LogName system -entrytype Error, Warning -After (Get-Date).AddDays(-3)PS C:\temp\PowerShell2> echo > test.ps1 cmdlet Write-Output at command pipeline position 1 Supply values for the following parameters: InputObject[0]: Get-EventLog system -newest 5 | Sort-Object eventid -descending InputObject[1]: Get-Process InputObject[2]: Get-Service InputObject[3]:Get-EventLog -LogName system -entrytype warning -After (Get-Date).AddDays(-3) | Where-Object {$_.Source -ne "disk"}Get-EventLog -Index 18308517 -Logname System | Format-List
PS C:\temp\PowerShell2> type test.ps1
Get-EventLog system -newest 5 | Sort-Object eventid -descending Get-Process Get-Service PS C:\temp\PowerShell2> powershell -ExecutionPolicy ByPass -File test.ps1
File Operation PowerShell
PS C:\SysInternals\sendmail> net use \\STATBSPDB\C$ password /USER:STATBSPDB\administrator The command completed successfully. PS C:\SysInternals\sendmail> Copy-Item \\STATBSPDB\c$\SysInternals\sendmail\EventDetail.txt . PS C:\SysInternals\sendmail> dir Directory: C:\SysInternals\sendmail Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/29/2009 11:02 AM 13589 CHANGELOG.txt -a--- 1/28/2017 11:00 PM 5 close-wait.txt -a--- 1/12/2017 1:16 PM 782 dbmem.sql -a--- 1/28/2017 11:01 PM 798 dbmem.txt -a--- 1/28/2017 11:20 PM 121856 EventDetail.txt -a--- 12/7/2016 3:15 PM 45501 eventlast3hrs.txt -a--- 1/28/2017 11:00 PM 255618 eventlast3hrs.xml -a--- 9/29/2009 11:03 AM 4701 README-BR.txt -a--- 9/29/2009 11:03 AM 8193 README.txt -a--- 9/29/2009 10:49 AM 1531966 sendEmail.exe -a--- 9/29/2009 1:46 PM 82448 sendEmail.pl -a--- 1/12/2017 3:02 PM 895 sendmail - Copy.cmd -a--- 1/20/2017 4:29 PM 907 sendmail.cmd -a--- 1/12/2017 2:57 PM 0 sqlcmd.log -a--- 9/29/2009 11:03 AM 1256 TODO.txt -a--- 5/13/2016 11:57 AM 66888 typeperf.htm -a--- 1/28/2017 11:00 PM 3594 typeperf.out -a--- 5/13/2016 12:22 PM 1170 typeperf.txt PS C:\SysInternals\sendmail> Copy-Item \\STATBSPDB\c$\SysInternals\sendmail\EventDetail_App.txt . PS C:\SysInternals\sendmail> dir PS C:\SysInternals\sendmail> Invoke-WebRequest -Uri "http://www.7-zip.org/a/7z1604-x64.msi" -OutFile "C:\SysInternals\7z1604-x64.msi" PS C:\SysInternals\sendmail> Start-Process "C:\SysInternals\7z1604-x64.msi" /qn -Wait PS C:\SysInternals\sendmail> cd 'C:\Program Files\7-Zip' PS C:\Program Files\7-Zip> .\7z.exe a C:\SysInternals\sendmail\EventDetail.zip C:\SysInternals\sendmail\EventDetail* 7-Zip [64] 16.04 : Copyright (c) 1999-2016 Igor Pavlov : 2016-10-04 Scanning the drive: 2 files, 29325476 bytes (28 MiB) Creating archive: C:\SysInternals\sendmail\EventDetail.zip Items to compress: 2 Files read from disk: 2 Archive size: 482093 bytes (471 KiB) Everything is Ok PS C:\Program Files\7-Zip> cd C:\SysInternals\sendmail\ PS C:\SysInternals\sendmail> dir Directory: C:\SysInternals\sendmail Mode LastWriteTime Length Name ---- ------------- ------ ---- -a--- 9/29/2009 11:02 AM 13589 CHANGELOG.txt -a--- 1/29/2017 12:00 AM 5 close-wait.txt -a--- 1/12/2017 1:16 PM 782 dbmem.sql -a--- 1/29/2017 12:01 AM 798 dbmem.txt -a--- 1/28/2017 11:20 PM 121856 EventDetail.txt -a--- 1/29/2017 12:29 AM 482093 EventDetail.zip -a--- 1/28/2017 11:33 PM 29203620 EventDetail_App.txt -a--- 12/7/2016 3:15 PM 45501 eventlast3hrs.txt -a--- 1/29/2017 12:00 AM 260753 eventlast3hrs.xml -a--- 9/29/2009 11:03 AM 4701 README-BR.txt -a--- 9/29/2009 11:03 AM 8193 README.txt -a--- 9/29/2009 10:49 AM 1531966 sendEmail.exe -a--- 9/29/2009 1:46 PM 82448 sendEmail.pl -a--- 1/12/2017 3:02 PM 895 sendmail - Copy.cmd -a--- 1/20/2017 4:29 PM 907 sendmail.cmd -a--- 1/12/2017 2:57 PM 0 sqlcmd.log -a--- 9/29/2009 11:03 AM 1256 TODO.txt -a--- 5/13/2016 11:57 AM 66888 typeperf.htm -a--- 1/29/2017 12:00 AM 3595 typeperf.out -a--- 5/13/2016 12:22 PM 1170 typeperf.txt PS C:\SysInternals\sendmail> .\sendEmail -o -a EventDetail.zip -f spadmin@nso.go.th -t nutthaphon@gmail.com -s mailgw.nso.go.th:25 -u "Event Viewer" -m "FYI" Jan 29 00:30:30 statbspapp sendEmail.exe[213848]: Email was sent successfully! PS C:\SysInternals\sendmail>
SQL Server PowerShell
First of all, enable scripting restriction then load sqlps module.
PS C:\Users\Administrator\Documents> Set-ExecutionPolicy RemoteSigned PS C:\Users\Administrator\Documents> Import-Module sqlps -DisableNameChecking PS SQLSERVER:\>
Try it
PS SQLSERVER:\> Invoke-Sqlcmd -Query "SELECT GETDATE() AS TimeOfQuery;" -ServerInstance "STATBSPDB" –Username "sa" –Password "p@ssw0rd "-- or --
PS SQLSERVER:\> Invoke-Sqlcmd -ServerInstance . -Database master -Query "select GetDate()" Column1 ------- 19-Jan-17 2:54:07 PM
cd SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases> cd WSS_Content PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\WSS_Content> Invoke-Sqlcmd -Query "SELECT DB_NAME() as [Database]" WARNING: Using provider context. Server = STATBSPDB, Database = WSS_Content. Database -------- WSS_Content PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\WSS_Content>
PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\WSS_Content> ls tables -Force Schema Name Created ------ ---- ------- dbo AllDocs 02-May-14 3:46 PM dbo AllDocVersions 02-May-14 3:46 PM dbo AllFileFragments 02-May-14 3:46 PM dbo AllLinks 02-May-14 3:46 PM dbo AllLists 02-May-14 3:46 PM dbo AllListsAux 02-May-14 3:46 PM dbo AllListsItemCount 02-May-14 3:46 PM dbo AllListsPlus 02-May-14 3:46 PM dbo AllListUniqueFields 02-May-14 3:46 PM dbo AllLookupRelationships 02-May-14 3:46 PM dbo AllSites 02-May-14 3:46 PM dbo AllUserData 02-May-14 3:46 PM dbo AllUserDataJunctions 02-May-14 3:46 PM dbo AllWebParts 02-May-14 3:46 PM dbo AllWebs 02-May-14 3:46 PM
PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\master> Set-Location SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\master PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\master> sql "select * from spt_monitor" WARNING: Using provider context. Server = STATBSPDB, Database = master. lastrun : 10-Feb-12 9:02:09 PM cpu_busy : 20 io_busy : 9 idle : 2707 pack_received : 39 pack_sent : 39 connections : 19 pack_errors : 0 total_read : 0 total_write : 0 total_errors : 0 PS SQLSERVER:\SQL\STATBSPDB\DEFAULT\Databases\master>
SharePoint PowerShell
Manual registration on Windows PowerShell
PS C:\Users\Administrator> C:\"Program Files"\"Common Files"\"microsoft shared"\"Web Server Extensions"\15\CONFIG\POWERSHELL\Registration\SharePoint.ps1
-- OR --
Add-PSSnapin Microsoft.SharePoint.Powershell
Networking PowerShell
Get-DnsClientCache Clear-DnsClientCache Get-DnsClientGlobalSetting Get-DnsClientServerAddress Resolve-DnsName xx.yy.zz -server 172.18.1.11 Get-NetIPAddress Get-NetIPInterface Get-NetRoute Get-NetTCPConnection Get-NetTCPSetting Get-NetAdapter Get-NetAdapterAdvancedProperty Get-NetAdapterStatistics
No comments:
Post a Comment