Categories
Sponsors
Archive
Blogroll
Badges
Community
|
Posted in Virtual Machine Manager, Windows Powershell, Windows Server | No Comment | 4,981 views | 28/07/2012 16:17
Best Hyper-V Linux Preparation tool SetLinuxvM v4.4 is out!
Changes:
* Fixed “Cannot connect to SCVMM Server” bug of SCVMM 2012 SP1.
* Added native “virtualmachinemanager” cmdlets support for SCVMM 2012 SP1.
* Added Linux Integration Services v3.3 as a default integration service.
* Added console keyboard language support. English is still default language. (Feature request from Jernej Zorko, Thanks!)
* SetLinuxVM no longer resumes operations if root password is not correct. (Feature request from Anonymous, Thanks!)
* Added System Center Config Manager Package Definition File for unattended installations.
* Enhanced installation/uninstallation support with Advanced Installer (Thanks to Advanced Installer!)
Now SetLinuxVM is even more perfect! Please go to official website to download latest version.
Again, thanks for using SetLinuxVM!
Posted in Windows Powershell | No Comment | 2,328 views | 15/07/2012 07:29
Function to test Wmi Objects
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
| function Test-WmiObject {
<#
.SYNOPSIS
Function to test Wmi Objects
.EXAMPLE
Test-WmiObject -NameSpace "root\virtualization" -WmiHost "hyperv01.yusufozturk.info"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'Wmi NameSpace. Example: root\virtualization')]
[string]$NameSpace,
[Parameter(
Mandatory = $false,
HelpMessage = 'Name of the Wmi Host. Example: Server01')]
[string]$WmiHost,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
if (!$WmiHost)
{
$CheckWmiObject = Get-WmiObject -Computer "." -Namespace "$NameSpace" -List -EA SilentlyContinue
if (!$CheckWmiObject)
{
$ResultCode = "-1"
$ResultMessage = "Could not contact with Wmi Provider."
}
else
{
$ResultCode = "1"
$ResultMessage = "Wmi Provider is available."
}
}
else
{
$CheckWmiObject = Get-WmiObject -Computer "$WmiHost" -Namespace "$NameSpace" -List -EA SilentlyContinue
if (!$CheckWmiObject)
{
$ResultCode = "-1"
$ResultMessage = "Could not contact with Wmi Provider."
}
else
{
$ResultCode = "1"
$ResultMessage = "Wmi Provider is available."
}
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
} |
function Test-WmiObject {
<#
.SYNOPSIS
Function to test Wmi Objects
.EXAMPLE
Test-WmiObject -NameSpace "root\virtualization" -WmiHost "hyperv01.yusufozturk.info"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'Wmi NameSpace. Example: root\virtualization')]
[string]$NameSpace,
[Parameter(
Mandatory = $false,
HelpMessage = 'Name of the Wmi Host. Example: Server01')]
[string]$WmiHost,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
if (!$WmiHost)
{
$CheckWmiObject = Get-WmiObject -Computer "." -Namespace "$NameSpace" -List -EA SilentlyContinue
if (!$CheckWmiObject)
{
$ResultCode = "-1"
$ResultMessage = "Could not contact with Wmi Provider."
}
else
{
$ResultCode = "1"
$ResultMessage = "Wmi Provider is available."
}
}
else
{
$CheckWmiObject = Get-WmiObject -Computer "$WmiHost" -Namespace "$NameSpace" -List -EA SilentlyContinue
if (!$CheckWmiObject)
{
$ResultCode = "-1"
$ResultMessage = "Could not contact with Wmi Provider."
}
else
{
$ResultCode = "1"
$ResultMessage = "Wmi Provider is available."
}
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
}
Example Usage: Test-WmiObject -NameSpace “root\virtualization” -WmiHost “hyperv01.yusufozturk.info”
Posted in Windows Powershell | No Comment | 1,877 views | 15/07/2012 07:05
Function to test PS Modules
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| function Test-PSModule {
<#
.SYNOPSIS
Function to test PS Modules
.EXAMPLE
Test-PSModule -Name "FailoverClusters"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Module Name. Example: FailoverClusters')]
[string]$Name,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
$CheckModule = Get-Module -Name $Name -EA SilentlyContinue
if (!$CheckModule)
{
$ImportModule = Import-Module -Name $Name -EA SilentlyContinue
$CheckModule = Get-Module -Name $Name -EA SilentlyContinue
if (!$CheckModule)
{
$ResultCode = "-1"
$ResultMessage = "$Name Module is not available."
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Module is imported."
}
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Module is already imported."
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
} |
function Test-PSModule {
<#
.SYNOPSIS
Function to test PS Modules
.EXAMPLE
Test-PSModule -Name "FailoverClusters"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Module Name. Example: FailoverClusters')]
[string]$Name,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
$CheckModule = Get-Module -Name $Name -EA SilentlyContinue
if (!$CheckModule)
{
$ImportModule = Import-Module -Name $Name -EA SilentlyContinue
$CheckModule = Get-Module -Name $Name -EA SilentlyContinue
if (!$CheckModule)
{
$ResultCode = "-1"
$ResultMessage = "$Name Module is not available."
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Module is imported."
}
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Module is already imported."
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
}
Example Usage: Test-PSModule -Name “FailoverClusters”
Posted in Windows Powershell | No Comment | 2,032 views | 15/07/2012 07:03
Function to test PS Snapins.
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| function Test-PSSnapin {
<#
.SYNOPSIS
Function to test PS Snapins
.EXAMPLE
Test-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Snapin Name. Example: Microsoft.SystemCenter.VirtualMachineManager')]
[string]$Name,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
$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)
{
$ResultCode = "-1"
$ResultMessage = "$Name Snapin is not available."
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Snapin is added."
}
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Snapin is already loaded."
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
} |
function Test-PSSnapin {
<#
.SYNOPSIS
Function to test PS Snapins
.EXAMPLE
Test-PSSnapin -Name "Microsoft.SystemCenter.VirtualMachineManager"
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param (
[Parameter(
Mandatory = $true,
HelpMessage = 'PowerShell Snapin Name. Example: Microsoft.SystemCenter.VirtualMachineManager')]
[string]$Name,
[Parameter(
Mandatory = $false,
HelpMessage = 'XML output')]
[switch]$OutXML = $false
)
$ErrorActionPreference = "silentlycontinue"
$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)
{
$ResultCode = "-1"
$ResultMessage = "$Name Snapin is not available."
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Snapin is added."
}
}
else
{
$ResultCode = "1"
$ResultMessage = "$Name Snapin is already loaded."
}
if ($OutXML)
{
New-XML -ResultCode $ResultCode -ResultMessage $ResultMessage
}
else
{
$Properties = New-Object Psobject
$Properties | Add-Member Noteproperty ResultCode $ResultCode
$Properties | Add-Member Noteproperty ResultMessage $ResultMessage
Write-Output $Properties
}
}
Example Usage: Test-PSSnapin -Name “Microsoft.SystemCenter.VirtualMachineManager”
Posted in Windows Powershell | No Comment | 2,896 views | 14/07/2012 22:00
If you need to get a mimetype of extension, then you can use this function:
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
| function Get-MimeType
{
param ($Extension)
switch ($Extension)
{
.ps1 {"text/ps1"}
.psxml {"text/psxml"}
.psapi {"text/psxml"}
.posh {"text/psxml"}
.html {"text/html"}
.htm {"text/html"}
.php {"text/php"}
.css {"text/css"}
.jpeg {"image/jpeg"}
.jpg {"image/jpeg"}
.gif {"image/gif"}
.ico {"image/x-icon"}
.flv {"video/x-flv"}
.swf {"application/x-shockwave-flash"}
.js {"text/javascript"}
.txt {"text/plain"}
.rar {"application/octet-stream"}
.zip {"application/x-zip-compressed"}
.rss {"application/rss+xml"}
.xml {"text/xml"}
.png {"image/png"}
.mpg {"video/mpeg"}
.mpeg {"video/mpeg"}
.mp3 {"audio/mpeg"}
.woff {"application/x-font-woff"}
default {"text/html"}
}
} |
function Get-MimeType
{
param ($Extension)
switch ($Extension)
{
.ps1 {"text/ps1"}
.psxml {"text/psxml"}
.psapi {"text/psxml"}
.posh {"text/psxml"}
.html {"text/html"}
.htm {"text/html"}
.php {"text/php"}
.css {"text/css"}
.jpeg {"image/jpeg"}
.jpg {"image/jpeg"}
.gif {"image/gif"}
.ico {"image/x-icon"}
.flv {"video/x-flv"}
.swf {"application/x-shockwave-flash"}
.js {"text/javascript"}
.txt {"text/plain"}
.rar {"application/octet-stream"}
.zip {"application/x-zip-compressed"}
.rss {"application/rss+xml"}
.xml {"text/xml"}
.png {"image/png"}
.mpg {"video/mpeg"}
.mpeg {"video/mpeg"}
.mp3 {"audio/mpeg"}
.woff {"application/x-font-woff"}
default {"text/html"}
}
}
It’s simple but covers what you are really looking for.
Posted in Windows Powershell | No Comment | 5,554 views | 14/07/2012 21:56
You may need to get a directory content and output it as HTML.
Here is an example code of PoSHServer:
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
36
37
| function Get-DirectoryContent
{
param ($Path, $HeaderName, $RequestURL, $SubfolderName)
@"
<html>
<head>
<title>$($HeaderName)</title>
</head>
<body>
<h1>$($HeaderName) - $($SubfolderName)</h1>
<hr>
"@
$ParentDirectory = $RequestURL + $Subfoldername + "../"
@"
<a href="$($ParentDirectory)">[To Parent Directory]</a><br><br>
<table cellpadding="5">
"@
$Files = (Get-ChildItem "$Path")
foreach ($File in $Files)
{
$FileURL = $RequestURL + $Subfoldername + $File.Name
if (!$File.Length) { $FileLength = "[dir]" } else { $FileLength = $File.Length }
@"
<tr>
<td align="right">$($File.LastWriteTime)</td>
<td align="right">$($FileLength)</td>
<td align="left"><a href="$($FileURL)">$($File.Name)</a></td>
</tr>
"@
}
@"
</table>
<hr>
</body>
</html>
"@
} |
function Get-DirectoryContent
{
param ($Path, $HeaderName, $RequestURL, $SubfolderName)
@"
<html>
<head>
<title>$($HeaderName)</title>
</head>
<body>
<h1>$($HeaderName) - $($SubfolderName)</h1>
<hr>
"@
$ParentDirectory = $RequestURL + $Subfoldername + "../"
@"
<a href="$($ParentDirectory)">[To Parent Directory]</a><br><br>
<table cellpadding="5">
"@
$Files = (Get-ChildItem "$Path")
foreach ($File in $Files)
{
$FileURL = $RequestURL + $Subfoldername + $File.Name
if (!$File.Length) { $FileLength = "[dir]" } else { $FileLength = $File.Length }
@"
<tr>
<td align="right">$($File.LastWriteTime)</td>
<td align="right">$($FileLength)</td>
<td align="left"><a href="$($FileURL)">$($File.Name)</a></td>
</tr>
"@
}
@"
</table>
<hr>
</body>
</html>
"@
}
It’s really like IIS outputs :)
Posted in Windows Powershell | No Comment | 2,944 views | 14/07/2012 21:52
Your Powershell scripts binding some ports to server ip address? Then you need to check ip address before to avoid from issues.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| function Confirm-PoSHServerIP
{
param ($IP)
# Get Networking Adapter Configuration
$IPConfigs = Get-WmiObject Win32_NetworkAdapterConfiguration
# Get All IP Addresses
foreach ($IPConfig in $IPConfigs)
{
if ($IPConfig.IPaddress)
{
foreach ($IPAddress in $IPConfig.IPaddress)
{
if ("$IP" -eq "$IPAddress")
{
$Result = "Validated"
}
}
}
}
$Result
} |
function Confirm-PoSHServerIP
{
param ($IP)
# Get Networking Adapter Configuration
$IPConfigs = Get-WmiObject Win32_NetworkAdapterConfiguration
# Get All IP Addresses
foreach ($IPConfig in $IPConfigs)
{
if ($IPConfig.IPaddress)
{
foreach ($IPAddress in $IPConfig.IPaddress)
{
if ("$IP" -eq "$IPAddress")
{
$Result = "Validated"
}
}
}
}
$Result
}
If you get “Validated” as a output, then you can be sure that, ip address is exist on server.
|