PSSessionは同時接続数の制限があるので、毎回作成してるとすぐに枯渇します。 このためセッション名を付与し、再利用可能であれば使いまわします。
以下、接続サンプル
#Session parameter
$params=@{
ComputerName = $ipAddress| #if ComputerName is not supplied. Connect to "internetbeacon.msedge.net" by default | |
| Test-NetConnection | |
| #Test ping(ICMP protocol) | |
| Test-NetConnection "google.com" | |
| #Ping with TraceRoute | |
| Test-NetConnection "google.com" -TraceRoute | |
| #Set Remote ComputerName |
| #Requires -Version 3 | |
| #Credential file path | |
| $script:CredentialsFile = Join-Path $env:TEMP "SavedCredentials\Credentials.xml" | |
| function Set-SavedCredential() | |
| { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory)] |
| function Get-EventLogError | |
| { | |
| [CmdletBinding()] | |
| param( | |
| [Parameter(Mandatory,ParameterSetName="FromLastBootupTime")] | |
| [switch] $FromLastBootupTime, | |
| [Parameter(Mandatory,ParameterSetName="FromLastQueryTime")] | |
| [switch] $FromLastQueryTime, | |
| [Parameter(Mandatory,ParameterSetName="Range")] | |
| [DateTime] $From, |
| #Install SysInternals BGInfo/AutoLogon tools | |
| function Install-SysInternalsTool | |
| { | |
| #Target directory is %WinDir%C:\Windows\System32\SysInternals | |
| $targetDir = Join-Path $env:WinDir "System32\SysInternals" | |
| #Tools to be downloaded | |
| $tools = @{ | |
| Bginfo = "http://live.sysinternals.com/Bginfo.exe" | |
| Autologon = "http://live.sysinternals.com/Autologon.exe" |
| #Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542> | |
| function Test-RebootRequired | |
| { | |
| $result = @{ | |
| CBSRebootPending =$false | |
| WindowsUpdateRebootRequired = $false | |
| FileRenamePending = $false | |
| SCCMRebootPending = $false | |
| } |
| function Install-ManagementStudio | |
| { | |
| [CmdletBinding()] | |
| param( | |
| $ImagePath, | |
| $WinSxS | |
| ) | |
| Set-StrictMode -Version Latest | |
| $ErrorActionPreference = "Stop" | |
| function Install-VisualStudio | |
| { | |
| [CmdletBinding()] | |
| param ( | |
| [string] $ImagePath, | |
| [string[]] $ArgumentList, | |
| [string] $InstallPath, | |
| [string] $ProductKey | |
| ) | |
| Write-Verbose "Install Visual Studio 2012..." |