Skip to content

Instantly share code, notes, and snippets.

View kkamegawa's full-sized avatar

KAMEGAWA Kazushi kkamegawa

View GitHub Profile
@kkamegawa
kkamegawa / Reset-HWNIC.ps1
Last active August 29, 2015 14:10
Reset Hardware NIC
if ([System.Diagnostics.EventLog]::SourceExists("PowerShellScriptEvent") -eq $false){
New-EventLog -LogName Application -Source PowerShellScriptEvent
}
Get-NetAdapterHardwareInfo | Restart-NetAdapter -Confirm:$false
Write-EventLog -LogName Application -EntryType Error -Source PowerShellScriptEvent -EventId 1 -Message "Reset HW NIC"
@kkamegawa
kkamegawa / Reset-HWNICTask.xml
Created November 30, 2014 19:50
Call Reset-HWNIC.ps1 task on Server start delay 15 min.
<?xml version="1.0" encoding="UTF-16"?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.4">
<RegistrationInfo>
<Date>2014-12-01T04:34:23.796031</Date>
<Author>.\administrator</Author>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
<Subscription><QueryList><Query Id="0" Path="System"><Select Path="System">*[System[Provider[@Name='Microsoft-Windows-Kernel-General'] and EventID=12]]</Select></Query></QueryList></Subscription>
@kkamegawa
kkamegawa / backup-vmdisk-2008r2.ps1
Created December 4, 2014 20:09
Hyper-V's VHD backup only Windows Server 2008 R2. Use http://pshyperv.codeplex.com.
#this script can run under pshyperv.codeplex.com's module
Import-Module 'C:\Program Files\modules\HyperV'
if ([System.Diagnostics.Eventing]::sourceExists('PowerShellScript') -eq $false){
new-eve -logname Application -source 'PowerShellScript'
}
[string]$message = ""
#hyper-v's vm name can only NTFS's compatibile name
$targets = 'Server1','Server2'
#backup root folder
$destinationRoot = 'E:\HyperVBackup'
@kkamegawa
kkamegawa / Show-TaskSchedule.ps1
Created December 13, 2014 02:10
Task Scheduler will run information.
Get-ScheduledTask | Where {$_.State -eq 'Ready'} | Get-ScheduledTaskInfo | where {$_.nextruntime -ne $null} | select taskpath,taskname,nextruntime
@kkamegawa
kkamegawa / Get-OfficeTime.ps1
Created December 13, 2014 22:42
Show working time in office. I checked Vista, and Windwos 7.
$date = [datetime]::today.adddays(-1)
$events = Get-EventLog -LogName system -before $date | where-object {$_.source.startswith("Microsoft-Windows-Kernel") -eq $true -or $_.source.startswith("Microsoft-Windows-Power") -eq $true} | select-object timegenerated,source,InstanceID
$poweron = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-General" -and $_.InstanceID -eq 12}
$shutdown = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-General" -and $_.InstanceID -eq 13}
$sleepwakeup = $events | where-object {$_.source -eq "Microsoft-Windows-Power-Troubleshooter" -and $_.InstanceID -eq 1}
$sleepgo = $events | where-object {$_.source -eq "Microsoft-Windows-Kernel-Power" -and $_.InstanceID -eq 42}
$workend = $shutdown[0].TimeGenerated
if($sleepgo -ne $null) {
if($shutdown[0].TimeGenerated -lt $sleepgo[0].TimeGenerated) {
@kkamegawa
kkamegawa / remove-sqllogs.ps1
Last active August 29, 2015 14:12
Remove old SQL Server Transaction log, and Backup log, dump files.
#remove sql server old files
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoExtended")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.ConnectionInfo")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SmoEnum")
#create a new server object
$server = New-Object ("Microsoft.SqlServer.Management.Smo.Server") "(local)"
$backupDirectory = $server.BackupDirectory
$folders = get-childitem $backupDirectory -Directory
@kkamegawa
kkamegawa / xslxNamespace.cs
Last active August 29, 2015 14:14
Create OpenXML Spreadsheet's xml namespace in LINQ to XML.
using System.Xml.Linq;
namespace XslxNameSpaceSample
{
class Program
{
static void XNamespaceSample()
{
const string openXmlMarkupSchema = "http://schemas.openxmlformats.org/markup-compatibility/2006";
const string spreadSheetSchema = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac";
@kkamegawa
kkamegawa / Choice-AzureSubscription.ps1
Last active February 14, 2017 20:48
Choice Azure Subscription PowerShell Script
function Choice-AzureSubscription
{
$appdata = [environment]::GetFolderPath("Applicationdata")
$jsonFile = Join-Path $appdata -childpath "Windows Azure Powershell" | join-path -ChildPath "AzureProfile.json"
$json = get-content $jsonFile -encoding UTF8 -raw | ConvertFrom-Json
if($json.Subscriptions.Count -gt 1) {
for($index = 0;$index -lt $json.Subscriptions.Count;$index++){
write-host $index ":" $json.Subscriptions[$index].Name
}
@kkamegawa
kkamegawa / list-backupfiles.ps1
Created November 15, 2015 04:00
create backup file list to HTML in Windows Server 2012 R2.
$OnPremisePolicy = Get-WBPolicy
$Backups = @{
Folder = $Folder
FileName = $FileName
}
$BackupList = @()
foreach($backup in $OnPremisePolicy){
@kkamegawa
kkamegawa / 2015-nov-18-vso.md
Last active November 20, 2015 00:52
about Visual Studio Team Services

Connect();でVisual Studio Onlineの大幅な変更がアナウンスされました。いくつか紹介します。元ネタhttps://www.visualstudio.com/en-us/news/2015-nov-18-vso.aspx

Visual Studio Team Serviceになりました

Visual Studio Onlineという名前でしたが、本日付でVisual Studio Team Servicesに変わります。以前Visual Studio 2008のころはVisual Studio Team Systemという名前でしたが、略称は同じVSTSということですね(^^;。 URLおよび、VS OnlineはブラウザベースのIDEとしてのVisualStudio.comはそのまま生き残ります。

拡張機能とマーケットプレイス

Visual Studio Team Servicesでは今日からMarketPlaceをサポートします。拡張機能はTeam Serviceに統合され、既存の機能を拡張します。カスタムコントロール、コンテキストメニュー、ダッシュボードのウィジェット、ビルド、リリースタスクなどを拡張することができます。

マーケットプレイスではVisual Studioの新しい機能を見つけることができます。Visual Studio Team ServicesとVisual Studio Codeの拡張機能もも見つけることができます。