ersin.fr
msgbartop
just my personal notebook…
msgbarbottom


27 Dec 16 Listing windows services statuses with Powershell

Advertisements
$stopingServices=Get-Service | Where-Object {$_.status -eq "stoping"}
$startingServices=Get-Service | Where-Object {$_.status -eq "starting"}
$runningServices=Get-Service | Where-Object {$_.status -eq "running"}
$stoppedServices=Get-Service | Where-Object {$_.status -eq "stopped"}


if($startingServices){
 Write-Host "`nStarting Services: $startingServices"
}
if($stopingServices){
 Write-Host "`nStoping Services: $stopingServices"
}
if($runningServices){
 Write-Host "`nRunning Services: $runningServices"
}
if($stoppedServices){
 Write-Host "`nStopped Services: $stoppedServices"
}

Tags:

23 Nov 16 view the registry entries with powershell

Get-ItemProperty -Path Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation

royal-ts-suygulama-yonetimidosyalarersinersin

Tags: ,

03 Aug 16 Listing IIS Application Pool Memory usage in PowerShell

Open Powershell as an Administrator on the web server, then run:

$apmem= gwmi -ComputerName localhost -NS 'root\WebAdministration' -class 'WorkerProcess' | select PSComputerName, AppPoolName,ProcessId , @{n='RAM';e={ [math]::round((Get-Process -Id $_.ProcessId -ComputerName $_.PSComputerName).WorkingSet / 1Mb) }} | sort RAM -Descending | ft -AutoSize

echo $apmem

You should see something like:

PS C:\Windows\system32> C:\scripts\appool.ps1

PSComputerName AppPoolName ProcessId RAM
-------------- ----------- --------- ---
MYSERVER01 ersinakyuz.com 2352 1150
MYSERVER01 kutuphaneleriseviyorum.org 6184 729
MYSERVER01 perlmonks.com 3444 646

If you get Get-WmiObject : Could not get objects from namespace root/WebAdministration. Invalid namespace then you need to enable the IIS Management Scripts and Tools feature using:

ipmo ServerManager
Add-WindowsFeature Web-Scripting-Tools

13 Jul 16 CredSSP authentication problem in Powershell Remote Queries

If you receive the following error while running remote .exe files from in powershell.

UNKNOWN: WEB SERVICE STATUS [vmserver01] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. CredSSP authentication is currently disabled in the client configuration. Change the client configuration and try the request again. CredSSP authentication must also be enabled in the server configuration. Also, Group Policy must be edited to allow credential delegation to the target computer. Use gpedit.msc and look at the following policy: Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Delegating Fresh Credentials.  Verify that it is enabled and configured with an SPN appropriate for the target computer. For example, for a target computer name “myserver.domain.com”, the SPN can be one of the following: WSMAN/myserver.domain.com or WSMAN/*.domain.com For more information, see the about_Remote_Troubleshooting Help topic.

Resolution:

Use below cmdlet enable CredSSP on the server by specifying Server in Role

Enable-WSManCredSSP -Role “Server”

credssp

 

for more info: https://technet.microsoft.com/en-us/library/hh849872.aspx

07 Jan 16 How to troubleshoot memory issues when executing remote Powershell queries

If you are receiving “Processing data for a remote command failed with the following error message: The WSMan provider” message from the PS Queries (e.g. on the Nagios)

All you have to do is log on the target computer, and run powershell with Administrator Rights. Then you can increase Powershell memory with below commands

You can get current memory size with get-item:

Get-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB

 

And here is the command for change the value:

Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 250 -Force

or

winrm set winrm/config/winrs @{MaxMemoryPerShellMB=”512″}

 

powershellmemory

 

In some cases, you need to restart the WinRM service on target system:

Restart-Service winrm

18 Dec 15 Catching Out Of Memory Exceptions in PowerShell

Catch [System.OutOfMemoryException]{
     bla bla bla...
 }

30 Nov 15 Installing Powershell ISE via Powershell commands

Using PowerShell

  1. Open Powershell Window
  1. Execute following cmdlets.
Import-Module ServerManager

Add-WindowsFeature PowerShell-ISE

Tags:

28 Apr 15 How to connect Oracle DB with PowerShell

# Load the ODP assembly 
[Reflection.Assembly]::LoadFile("C:\oracle\11.2.0\client_2\odp.net\bin\4\Oracle.DataAccess.dll")|Out-Null
# 
#vars&cons
$stations =@{
"424"="Istanbul";
"421"="İzmir"
}
$dbuser="user"
$dbpasswd="password"

connect to Oracle


$constr =
"
User Id=$dbuser;
Password=$dbpasswd;
Data Source=CITIES
"
$conn= New-Object Oracle.DataAccess.Client.OracleConnection($constr)
$conn.Open()

Create a datareader for a SQL statement

$sql="select stationid
from CITIES.SWITCHPARAMETER
where switchid = '2'
"
$command = New-Object Oracle.DataAccess.Client.OracleCommand( $sql,$conn)
$reader=$command.ExecuteReader()

Write out the results

# 
while ($reader.read()) {
$stationID=$reader.GetString(0)
$stationname=$stations.Get_Item($stationID)
Write-Host
"
Station ID: $stationID ($stationname)"
}

Tags: ,