0
2.ps1
スクリプトを呼び出す1.ps1
スクリプトを作成しました。 2.ps1
を呼び出した後、$variable
で何らかの結果が得られます。この$variable
の結果を私の1.ps1
の操作で使用します。2番目のpowershellスクリプトから1番目のPowerShellスクリプトに変数値を返しますか?
$csv = Get-Content \\10.46.198.141\try\windowserver.csv
foreach ($servername in $csv) {
$TARGET = $servername
$ProfileName = "CustomPowershell"
$SCRIPT = "powershell.exe -ExecutionPolicy Bypass -File '\\10.46.198.141\try\disk_space.ps1' '$servername'"
$HubRobotListPath = "C:\Users\Automation\Desktop\hubrobots.txt"
$UserName = "aaaaa"
$Password = "aaaaaaa"
$Domain = "SW02111_domain"
$HubOne = "sw02111"
#lots of code here
}
今私は2番目のスクリプトがあります:私は最初のPowerShellスクリプトのコードでCSVファイルを作成するには、この$final
出力を使用したい
Param([string]$servername)
$hash = New-Object PSObject -Property @{
Servername = "";
UsedSpace = "";
DeviceID = "";
Size = "";
FreeSpace = ""
}
$final [email protected]()
$hashes [email protected]()
$hash = New-Object PSObject -Property @{
Servername = $servername;
UsedSpace = "";
DeviceID = "";
Size = "";
FreeSpace = ""
}
$hashes += $hash
$space = Get-WmiObject Win32_LogicalDisk
foreach ($drive in $space) {
$a = $drive.DeviceID
$b = [System.Math]::Round($drive.Size/1GB)
$c = [System.Math]::Round($drive.FreeSpace/1GB)
$d = [System.Math]::Round(($drive.Size - $drive.FreeSpace)/1GB)
$hash = New-Object PSObject -Property @{
Servername = "";
UsedSpace = $d;
DeviceID = $a;
Size = $b;
FreeSpace = $c
}
$hashes += $hash
}
$final += $hashes
return $final
:
$final | Export-Csv C:\Users\Automation\Desktop\disk_space.csv -Force -NoType
'Get-WmiObject -Class Win32_logicaldisk -ComputerName $ servername' – JosefZ