Set PATH system-wide
$newPath = $env:Path
$newPath += ";C:\YournewPath" #see that ; at the begining is fuckin important!
[Environment]::SetEnvironmentVariable("Path",$newPath,[EnvironmentVariableTarget]::Machine)
#restart powershell
Add Windows service from command line (create)
sc create <servicename> binpath= "<pathtobinaryexecutable>" [option1] [option2] [optionN]
The trick is to leave a space after the =
in your create statement, and also to use " "
for anything containing special characters or spaces.
Use .NET type (assembly) from PowerShell
Add-Type -AssemblyName System.ServiceProcess
Get SID for account
$objUser = New-Object System.Security.Principal.NTAccount("user")
$strSID = $objUser.Translate([System.Security.Principal.SecurityIdentifier])
$strSID.Value
wget (Invoke-WebRequest) download file
Works in PowerShell 2.0
:
$url = "###"
$fileName = "test.rar"
(New-Object System.Net.WebClient).DownloadFile($url,$($pwd.ToString() +"\$fileName"))
Run SQL from PowerShell
Import-Module SqlPs
Invoke-SqlCmd "select * from FROM [sharepoint_fba_db].[dbo].[aspnet_Users]"
Convert to JPG from PNG
function ConvertTo-Jpg
{
[cmdletbinding()]
param([Parameter(Mandatory=$true, ValueFromPipeline = $true)] $Path)
process{
if ($Path -is [string])
{ $Path = get-childitem $Path }
$Path | foreach {
$image = [System.Drawing.Image]::FromFile($($_.FullName));
$FilePath = [IO.Path]::ChangeExtension($_.FullName, '.jpg');
$image.Save($FilePath, [System.Drawing.Imaging.ImageFormat]::Jpeg);
$image.Dispose();
}
}
}
#Use function:
#Cd to directory w/ png files
cd .\bin\pngTest
#Run ConvertTo-Jpg function
Get-ChildItem *.png | ConvertTo-Jpg
Transform image to base64
[convert]::ToBase64String((get-content $path -encoding byte))
Hyper-V
Get VM IP address
Gets Virtual Machine network address
Get-VMNetworkAdapter Ubuntu16 | select IPAddresses
Enable VM inside VM (nested virtualization)
Set-VMProcessor -VMName <VMName> -ExposeVirtualizationExtensions $true
LINQ ZIP function for PowerShell
function Select-Zip {
[CmdletBinding()]
Param(
$First,
$Second,
$ResultSelector = { ,$args }
)
[System.Linq.Enumerable]::Zip($First, $Second, [Func[Object, Object, Object[]]]$ResultSelector)
}
No matches...