Skip to content

Instantly share code, notes, and snippets.

@jamessantiago
jamessantiago / Powershell.csx
Created December 27, 2013 06:46
MMBot script for use with the MMBot.Powershell package
//Notes:
//Requires the MMBot.Powershell nuget package
//Output objects must either support a ToString method or be a string to display properly
//It is recommended to use the PowershellModule script instead of this one to control what is executed
using MMBot.Powershell;
var robot = Require<Robot>();
robot.Respond(@"(ps|powershell) (.*)", msg =>
$logs = 'c:\windows\system32\ccm\logs\smstslog'
if (-not (test-path $logs))
{
exit 0
}
$tsenv = new-object -comobject Microsoft.SMS.TSEnvironment
$computer = ""
if ($tsenv -ne $null)
{
#you can use this as a script or just run these three commands one at a time
import-module bitstransfer
#kick off the transfer
start-bitstransfer -source "large file" -destination "folder" -asyncronous -displayname MyTransfer
#monitor transfer and restart if failed
1..1000|% {sleep (60); get-bitstransfer -name MyTransfer |% {if ($_.jobstate -eq "Transferring") {write-host $($_.bytestransfered / $_.bytestotal)} elseif ($_.jobstate -like "error") {resume-bitstransfer $_; "resuming after error"} elseif ($_.jobstate -like "Transferred") {complete-bitstransfer $_; exit}}
$a = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$ToTest = {
"AAAAAAA"
"AAAAAAAA"
"AAAAAAAAA"
"AAAAAAAAAA"
"AAAAAAAAAAA"
"AAAAAAAAAAAA"
"AAAAAAAAAAAAA"
@jamessantiago
jamessantiago / BitsFolderCopy.ps1
Last active December 11, 2015 20:09
Script to copy a directory using bits and retain it's structure
Import-Module BitsTransfer
$s = "C:\Source"
$d = "D:\Destination"
xcopy.exe /T /E $s $d
ls $s -Recurse |? {! $_.PSIsContainer} |% {
$e = $_.FullName.Remove(0, $s.Length + 1)
start-bitstransfer $($_.FullName) $d\$e
}