1
我目前正在創建一個AD腳本,可以獲取一臺機器的AD組並將它們傳輸到新機器(以防系統故障)。使用PowerShell'如果'語句來比較功能(Windows版本)
我設法讓腳本出去找到兩臺機器通過主機名運行的Windows版本,但是我在創建'if'語句來比較兩個版本的視窗。
這個想法是,如果是相同的版本(並因此相同的軟件包版本),這些組將自動複製,但我不能爲我的生活弄清楚如何做到這一點。
請考慮下面的代碼:
function W_version_current
{
$current = Get-WmiObject Win32_OperatingSystem -computer $current_hostname.text | select buildnumber
if ($current -match '7601')
{
"Windows 7"
}
elseif($current -match '2600')
{
"Windows XP"
}
elseif($current -eq $null)
{
"The box is empty"
}
else
{
"Function not supported"
}
}
function W_version_target
{
$target = Get-WmiObject Win32_OperatingSystem -computer $target_hostname.text | select buildnumber
if ($var -match '7601')
{
"Windows 7"
}
elseif($target -match '2600')
{
"Windows XP"
}
elseif($target -eq $null)
{
"The box is empty"
}
else
{
"Function not supported"
}
}
function compare_current_target
{
if(W_version_current -eq W_version_target)
{
"Matching version of Windows detected"
}
else
{
"Versions of Windows do not match"
}
}
現在是真的,所有的變量不能在函數外進行訪問?
如果是這樣,我還能做什麼?
那麼這是否意味着$ global:X =「hi」 - X是一個具有高值的全局變量? – obious 2012-04-21 18:47:56
答案更新:) – Nacht 2012-04-22 05:24:23
我會建議只是玩弄它 - 你會弄清楚它是如何工作很快 – Nacht 2012-04-22 05:25:01