Run Multiple Commands on Remote Machine
# Create a persistent connection to remote machine $Session = New-PSSession -ComputerName $Computer -Credential $Credential # Runs on remote machine Invoke-Command -Session $Session -ScriptBlock {Stop-Service -Name Bits} # Run on local machine Get-Service # Runs on remote machine again Invoke-Command -Session $Session -ScriptBlock {Start-Service -Name Bits}
Run Command on Remote Machine with Credentials
$Credential = Get-Credential Invoke-Command -ComputerName $Computer -ScriptBlock {Stop-Service -Name Bits} -Credential $Credential
Run Command on Remote Machine
$Credential = Get-Credential Invoke-Command -ComputerName $Computer -ScriptBlock {Stop-Service -Name Bits}
Create PS Credential from Strings
$Username = 'Username' $Password = 'Password' $SecureString = ConvertTo-SecureString $Password -AsPlainText -Force $Credential = New-Object System.Management.Automation.PSCredential $Username, $SecureString
Find characters between single quotes ‘
$string = "'LastName', ([samaccountname])" [Regex]::Matches($string, "(?
Convert Between Time Zones
$DateTime = [DateTime]::SpecifyKind($date, [DateTimeKind]::Unspecified) $from = [System.TimeZoneInfo]::FindSystemTimeZoneById($FromTimeZone) $to = [System.TimeZoneInfo]::FindSystemTimeZoneById($ToTimeZone) $utc = [System.TimeZoneInfo]::ConvertTimeToUtc($DateTime, $from) [System.TimeZoneInfo]::ConvertTime($utc, $to)
Search for a Time Zones
[System.TimeZoneInfo]::GetSystemTimeZones() | Where-Object{$_.DisplayName -like "*$($Name)*" -or $_.DaylightName -like "*$($Name)*" -or $_.StandardName -like "*$($Name)*" -or $_.Id -like "*$($Name)*"}