Skip to content

Instantly share code, notes, and snippets.

Avatar

KAMEGAWA Kazushi kkamegawa

View GitHub Profile
@kkamegawa
kkamegawa / Reset-HWNIC.ps1
Last active Aug 29, 2015
Reset Hardware NIC
View Reset-HWNIC.ps1
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 Nov 30, 2014
Call Reset-HWNIC.ps1 task on Server start delay 15 min.
View Reset-HWNICTask.xml
<?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 Dec 4, 2014
Hyper-V's VHD backup only Windows Server 2008 R2. Use http://pshyperv.codeplex.com.
View backup-vmdisk-2008r2.ps1
#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 Dec 13, 2014
Task Scheduler will run information.
View Show-TaskSchedule.ps1
Get-ScheduledTask | Where {$_.State -eq 'Ready'} | Get-ScheduledTaskInfo | where {$_.nextruntime -ne $null} | select taskpath,taskname,nextruntime
@kkamegawa
kkamegawa / Get-OfficeTime.ps1
Created Dec 13, 2014
Show working time in office. I checked Vista, and Windwos 7.
View Get-OfficeTime.ps1
$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 Aug 29, 2015
Remove old SQL Server Transaction log, and Backup log, dump files.
View remove-sqllogs.ps1
#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 Aug 29, 2015
Create OpenXML Spreadsheet's xml namespace in LINQ to XML.
View xslxNamespace.cs
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 Feb 14, 2017
Choice Azure Subscription PowerShell Script
View Choice-AzureSubscription.ps1
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 Nov 15, 2015
create backup file list to HTML in Windows Server 2012 R2.
View list-backupfiles.ps1
$OnPremisePolicy = Get-WBPolicy
$Backups = @{
Folder = $Folder
FileName = $FileName
}
$BackupList = @()
foreach($backup in $OnPremisePolicy){
@kkamegawa
kkamegawa / 2015-nov-18-vso.md
Last active Nov 20, 2015
about Visual Studio Team Services
View 2015-nov-18-vso.md

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の拡張機能もも見つけることができます。