Thursday, 29 June 2017

Stop, start disable services on multiple machines

$Machines = Get-Content -Path ".\Machines.txt"
$service="Microsoft Deployment Agent"
$credential = Get-Credential
foreach($computer in $Machines) {
    #$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).stopservice() 
    #$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).ChangeStartMode("Disabled") 
    $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).startservice()     
    $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).ChangeStartMode("Automatic") 
}
# $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).startservice() 
#Get-Service -Name $Services -ComputerName $Machines -Credential $credential | Set-Service -Status Started -StartupType Automatic 


As usual not really my code but plagiarised. Massive apologies to whoever/wherever I got it as I can’t find it again.  As usual – this is really for me!

The Get-Service /  Set-Service script was the obvious candidate to use but wont take a credential.

Put a list of machines in Machines.txt.

Original that I’ve lost also took a list of services!

Thursday, 8 June 2017

Grep for PowerShell

Get-Childitem -Path ".\" web.config -Recurse | Select-String -pattern 'dardaudit' –SimpleMatch

Works for me!

Monday, 8 May 2017

Resetting the product.

OK – so my audax applicaiton has not received an update in 4 months and I have just completed the paperwork for the Titanic Torr 2017.

Failed.

Thinking about it on my bike the MVP was far to big.

All I really want is a list of entrants details – that’s the MVP – one page – fill in the form.

To close for the North to the South and only a select few idiots elite riders do this but Antrim 300 will be a target!

WCF endpoints authentiction with HTTP and HTTPS

Add in a new endpoint
<endpoint contract="PortalServices.IMenuService" binding="webHttpBinding" address="restService" behaviorconfiguration="restJsonBehaviour" bindingconfiguration="WindowsHttpBindingHttps" />
With a binding confuguration for https with transport security mode.

<binding name="WindowsHttpBindingHttps">
          <security mode="Transport">
            <!-- Needs to be "TransportCredentialOnly" for Windows and "Transport" for https -->
            <transport clientcredentialtype="Windows" />
          </security>        
        </binding>

Enable https on the binding

<servicemetadata httpgetenabled="true" httpsgetenabled="true" />     

 


    
      
        
      
    
    
    
      
        
        
		
            
    
    
      
        
		     
          
          
        
      
    
    
      
        
          
            
            
          		 
        
		
          
            
            
          		 
        
        
          
            
          
        
      
    
  

Monday, 20 March 2017

KTA permissions for service accounts

Don’t ask – but heres a script to set permissions for KTA service accounts to run as non admins.

They also need lon on as service account permissions.

script to grant folder permission from here - http://techibee.com/powershell/grant-fullcontrol-permission-to-usergroup-on-filefolder-using-powershell/2158

param (

       [Parameter(Mandatory=$true)][string]$serviceAccount

) 



function Grant-userFullRights( [string[]]$Files, [string]$UserName) {           
 $rule=new-object System.Security.AccessControl.FileSystemAccessRule($UserName,"FullControl","Allow")            

 foreach($File in $Files) {            
  if(Test-Path $File) {            
   try {            
    $acl = Get-ACL -Path $File -ErrorAction stop            
    $acl.SetAccessRule($rule)            
    Set-ACL -Path $File -ACLObject $acl -ErrorAction stop            
    Write-Host "Successfully set permissions on $File"            
   } catch {            
    Write-Warning "$File : Failed to set perms. Details : $_"            
    Continue            
   }            
  } else {            
   Write-Warning "$File : No such file found"            
   Continue            
  }            
 }            
}
[string]$UserName = $serviceAccount

$Files = @("C:\ProgramData\Kofax\AppLogging\DB", "C:\ProgramData\Kofax Image Products\Local\Scripts")

Grant-userFullRights $Files $UserName
netsh http add urlacl http://+:80/Agility.Sdk.Services.StreamingService user=$UserName
netsh http add urlacl  http://+:3581/SALMetadata/ user=$UserName
netsh http add urlacl  http://+:3581/SAL/ user=$UserName
net stop "TotalAgility Streaming Service"
net start "TotalAgility Streaming Service"
net stop "KSALicenseService"
net start "KSALicenseService"

Tuesday, 14 February 2017

Powershell endpoints

For old school .svc and .asmx

foreach($dir in ("dir1",”dir2”)) {
    $files = Get-ChildItem -Path  D:\AppWebSites\$dir -Recurse -Include ('*.asmx','*.svc')
    $files
}

Friday, 3 February 2017

Quick event logging guide with MS EL–really for me

CONCEPTS

· Source = Only used by the Machine Event Viewer

· EventId  number that goes in the EventId column of database Log

· TraceEventType (System.Diagnostics.TraceEventType) = a system enum for the log level (info, verbose, error, critical)

PROJECT

We need to add a reference to these:

clip_image002

Config

This page explains it - https://msdn.microsoft.com/en-us/library/ff664760(v=pandp.50).aspx

Where is the tool?

The tool is in tfs - /EnterpriseLibrary5/Bin/EntLibConfig.exe

 

REGISTERING SOURCES FOR EVENTS LOG

If you ever need to register a source (for the Event Log), you run this from PowerShell

New-EventLog -LogName Application -SRC MyNewSource –computername <server>,<other>,<servers,go,here>

Is my source registered?

There’s a way to know what sources has been registered in a machine (see attached).

But it is easier to simply run the previous command to make sure