Posted in
Windows Powershell,
Windows Server |
No Comment | 2,662 views | 30/01/2012 01:36
Check-PSSnapin allows you to check specific PowerShell Snapin on server.
I’m using this function in SetLinuxVM 3.0 to check SCVMM if it’s available on server.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
| # Check Powershell Snapin
# Author: Yusuf Ozturk
# http://www.yusufozturk.info
function Check-PSSnapin
{
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Snapin Name. Example: Microsoft.SystemCenter.VirtualMachineManager')]
[string]$Name
)
$Success = "1";
$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
if (!$CheckSnapin)
{
$AddSnapin = Add-PSSnapin -Name $Name -EA SilentlyContinue
$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
if (!$CheckSnapin)
{
Write-Debug "$Name Snapin is not available."
}
else
{
Write-Debug "$Name Snapin is added."
$Success
}
}
else
{
Write-Debug "$Name Snapin is already loaded."
$Success
}
} |
# Check Powershell Snapin
# Author: Yusuf Ozturk
# http://www.yusufozturk.info
function Check-PSSnapin
{
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Snapin Name. Example: Microsoft.SystemCenter.VirtualMachineManager')]
[string]$Name
)
$Success = "1";
$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
if (!$CheckSnapin)
{
$AddSnapin = Add-PSSnapin -Name $Name -EA SilentlyContinue
$CheckSnapin = Get-PSSnapin -Name $Name -EA SilentlyContinue
if (!$CheckSnapin)
{
Write-Debug "$Name Snapin is not available."
}
else
{
Write-Debug "$Name Snapin is added."
$Success
}
}
else
{
Write-Debug "$Name Snapin is already loaded."
$Success
}
}
You can check PS Snapin like this:
Check-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager" |
Check-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager"
Name is mandatory, so you must give a name for that.