PowerShell script to get all IIS bindings and SSL certificates

Simple PowerShell script to get all bindings in Internet Information Services (IIS) and SSL certificates. Import-Module -Name WebAdministration Get-ChildItem -Path IIS:SSLBindings | ForEach-Object -Process ` { if ($_.Sites) { $certificate = Get-ChildItem -Path CERT:LocalMachine/My | Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint [PsCustomObject]@{ Sites = $_.Sites.Value CertificateFriendlyName = $certificate.FriendlyName CertificateDnsNameList = $certificate.DnsNameList CertificateNotAfter = $certificate.NotAfter CertificateIssuer […]

PowerShell Tip – How to install Windows Server roles and features and see parent / child relations as results?

It is very simple… Install-WindowsFeature -Name AD-Domain-Services, DNS -IncludeManagementTools -OutVariable result -Verbose Get-WindowsFeature -Name $result.FeatureResult.Name Note: GUIs are not recommended for the server. Install only AD-Domain-Services, DNS and RSAT-AD-PowerShell on your Windows Server Core and RSAT on your management server. Display Name Name Install State ———— —- ————- [X] Active Directory Domain Services AD-Domain-Services Installed [X] […]

PowerShell Tip – Convert Script Block to string or string to Script Block

It is very simple. You just need to create a new instance of System.Management.Automation.ScriptBlock and use Create() method. PowerShell code $scriptBlock1 = { Get-ChildItem } Write-Verbose -Message $scriptBlock1.GetType().FullName -Verbose $scriptBlockString = $scriptBlock.ToString() Write-Verbose -Message $scriptBlockString.GetType().FullName -Verbose $scriptBlock2 = [ScriptBlock]::Create($scriptBlockString) Write-Verbose -Message $scriptBlock2.GetType().FullName -Verbose # Execute& $scriptBlock2 Output VERBOSE: System.Management.Automation.ScriptBlock VERBOSE: System.String VERBOSE: System.Management.Automation.ScriptBlock

PowerShell Tip – How to set permissions that applies to folder, subfolder and files without iCacls?

It is very simple… $path = ‘C:\Temp’ New-Item -Path $path -ItemType directory $acl = Get-Acl -Path $path $permission = ‘Everyone’, ‘FullControl’, ‘ContainerInherit, ObjectInherit’, ‘None’, ‘Allow’ $rule = New-Object -TypeName System.Security.AccessControl.FileSystemAccessRule -ArgumentList $permission $acl.SetAccessRule($rule) $acl | Set-Acl -Path $path