param (
[Parameter(Mandatory=$true)][String]$certpath,
[Parameter(Mandatory=$true)][String]$certpass,
[Parameter(Mandatory=$true)][String]$ip,
[Parameter(Mandatory=$false)][String]$website = "Default Web Site"
)
$mypwd = ConvertTo-SecureString -String $certpass -Force –AsPlainText
$cert = Import-PfxCertificate -FilePath $certpath Cert:\LocalMachine\My -Password $mypwd -Exportable
$bind = Get-WebBinding -Protocol https -IPAddress $ip -port 443
if($bind -ne $null) {
Remove-WebBinding -Protocol https -IPAddress $ip -port 443
}
# -Name $website -IPAddress $ip -Protocol HTTPS -Port 443 -HostHeader '' -Binding $ip':433:'
new-WebBinding -Name $website -IPAddress $ip -Protocol https -Port 443
$bind = Get-WebBinding -Protocol https -IPAddress $ip -port 443
$bind.AddSslCertificate($cert.GetCertHashString(), "my")
This is for a cert to IP without host header.
Tuesday, 4 July 2017
Import and bind a cert is IIS.
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
}