Skip to content

Instantly share code, notes, and snippets.

@altrive
altrive / PSRemotingMemo.md
Last active December 20, 2015 04:19
PSRemotingメモ

1.PSSessionの作り方

PSSessionは同時接続数の制限があるので、毎回作成してるとすぐに枯渇します。 このためセッション名を付与し、再利用可能であれば使いまわします。

以下、接続サンプル

#Session parameter
$params=@{
    ComputerName   = $ipAddress
@altrive
altrive / Test-NetConnection.Tests.ps1
Last active November 12, 2019 16:22
PowerShell v4 new cmdlet "Test-NetConnection"
#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
@altrive
altrive / SavedCredential.ps1
Last active October 9, 2020 09:38
Credential management utilities for PowerShell
#Requires -Version 3
#Credential file path
$script:CredentialsFile = Join-Path $env:TEMP "SavedCredentials\Credentials.xml"
function Set-SavedCredential()
{
[CmdletBinding()]
param(
[Parameter(Mandatory)]
@altrive
altrive / Get-EventLogError.ps1
Last active November 12, 2019 16:22
PowerShell utility function to find EventLog errors.
function Get-EventLogError
{
[CmdletBinding()]
param(
[Parameter(Mandatory,ParameterSetName="FromLastBootupTime")]
[switch] $FromLastBootupTime,
[Parameter(Mandatory,ParameterSetName="FromLastQueryTime")]
[switch] $FromLastQueryTime,
[Parameter(Mandatory,ParameterSetName="Range")]
[DateTime] $From,
@altrive
altrive / PowerShellSyntaxHighlighterTest.md
Last active December 19, 2015 02:59
PowerShell Syntax Highlighter remove lines in some condition?.

Raw Text

START
::Test
[test]
test]::
[test::
[test]:
[test]::
@altrive
altrive / PowerShellv4_DynamicKeyword.md
Last active November 25, 2025 17:46
Test code of PowerShell v4 Dynamic Keyword

Define DynamicKeyword

Define DynamicKeyword 'ExecTest'

Note: Don't copy&paste from following code. PowerShell SyntaxHighlighter remove some lines. Instead, use RAW view.

#Requires -Version 4.0
Set-StrictMode -Version Latest
@altrive
altrive / Install-SysInternalsTool.ps1
Last active September 5, 2024 02:48
Install and setup script for SysInternals tools(BGInfo/AutoLogon).
#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"
@altrive
altrive / Test-RebootRequired.ps1
Last active May 26, 2026 13:42
Check pending reboot on local computer
#Based on <http://gallery.technet.microsoft.com/scriptcenter/Get-PendingReboot-Query-bdb79542>
function Test-RebootRequired
{
$result = @{
CBSRebootPending =$false
WindowsUpdateRebootRequired = $false
FileRenamePending = $false
SCCMRebootPending = $false
}
@altrive
altrive / Install-ManagementStudio.ps1
Last active December 15, 2015 21:39
SQL Server 2012 SP1 Express Management Studio unattend offline installer.
function Install-ManagementStudio
{
[CmdletBinding()]
param(
$ImagePath,
$WinSxS
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
@altrive
altrive / Install-VisualStudio.ps1
Last active March 29, 2024 14:27
Unattend install script for Visual Studio 2012 and Visual Studio 2012 Update 2
function Install-VisualStudio
{
[CmdletBinding()]
param (
[string] $ImagePath,
[string[]] $ArgumentList,
[string] $InstallPath,
[string] $ProductKey
)
Write-Verbose "Install Visual Studio 2012..."