Are you an IT Pro?
 Are you interested in information technologies?
  Technology Stronghold is the right place for you!

How to copy values of variables into PowerShell Script Block and keep it intact (remember it)?

There are situations where you need to create a script block, save it into variable and then execute it once or multiple times. Simply said, [ScriptBlock] is just an anonymous function so if you do this:

$scriptBlock = { $someVar }

& $scriptBlock

Then you will get someVar variable from the current scope or from the parent scope (dynamic scoping).

But what to do if you need to create a script block and keep intact all values of all variables? PowerShell 2.0 introduction …

Read More

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

Read More

PowerShell advanced function (cmdlet) - Report all VMs with disconnected NICs in the specified Virtual Machine Manager

This is very simple function to report all virtual machines in the defined System Center Virtual Machine Manager (SCVMM) with disconnected network adapters or with network adapters without specified VLAN.

Examples

Report

Get-RvSCVirtualNetworkAdapter -VMMServer firstVMM, secondVMM, thirdVMM -NoVMNetworkOrNoVLan | Out-GridView

Code

Function Get-RvSCVirtualNetworkAdapter

{

<#

.SYNOPSIS

Get network adapters of virtual machine on defined SCVMM server.

. …

Read More

PowerShell Tip - How to check number or cores, logical processors and Hyper-threading on multiple hosts?

It is very simple...

Get-CimInstance -ClassName Win32_Processor -CimSession host1, host2 | Format-Table PSComputerName, NumberOfCores, NumberOfLogicalProcessors

Read More

PowerShell advanced function (cmdlet) to get WWN (PWWN) of all cluster nodes

I wrote a very simple PowerShell script (Advanced Function) that will simplify process to add a new disk to any failover cluster (Hyper-V, SQL) that is connected to SAN via Fibre Channel.

If you need WWN (PWWN) of all nodes in the cluster then you need to know only a name of a single node or name of the cluster.

Examples

Enter node name

Get-ClusterNodeInitiatorPort -Cluster OneOfMyNode |

Export-Csv -Path 'C:\Temp\data.csv'

Enter cluster Name

Get-ClusterNodeInitiatorPort - …

Read More