$ErrorActionPreference = "Stop"
function Main
{
try
{
$logFilePath = 'C:\NotFound.log'
if (Test-Path $logFilePath)
{
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Execute as .ps1 | |
$text = @' | |
a | |
b | |
c | |
'@ | |
Write-Host $text.Length | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$templates = @' | |
権限 :{0} | |
グループ名: {1} | |
含まれているユーザー: | |
{2} | |
'@ | |
Add-Type -AssemblyName System.DirectoryServices | |
Add-Type -AssemblyName System.DirectoryServices.AccountManagement |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Need to execute in Visual Studio command prompt context | |
#ClientCertificate EKU | |
makecert.exe -r -pe -a sha256 -n "CN=Azure Management Certificate" -ss My -len 2048 -sy 24 -e "01/01/2040" -eku 1.3.6.1.5.5.7.3.2 AzureManagementCertificate.cer >$null | |
$cert = Get-Childitem Cert:\CurrentUser\My | where Subject -like "*Azure Management Certificate*" | |
makecert.exe -r -pe -a sha256 -n "CN=*.cloudapp.net" -sky exchange -len 2048 -e "01/01/2040" -cy end -eku "1.3.6.1.5.5.7.3.1" -sv temp.pvk cloudapp.net.cer > $null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = 'Stop' | |
function Main | |
{ | |
Use-NuGetPackage -PackageId Microsoft.IdentityModel.Clients.ActiveDirectory -Version 1.0.3 -Verbose #Require PSNuGet <https://github.com/altrive/PSNuGet> | |
#Azure AD native client application settings | |
$authority = 'https://login.windows.net/{0}.onmicrosoft.com' -f 'altrive' #Set AzureAD tenant | |
$clientId = '[Native Client Application ClientID]' #Native Client Application ClientID | |
$redirectUri = [Uri] 'http://localhost' #Dummy URL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
$RequestUrl = "http://127.0.0.1" | |
) | |
function Main | |
{ | |
$ErrorActionPreference = "Stop" | |
Add-Type -AssemblyName System.Net.Http | |
#Get ServicedPoint |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-LocalVariable | |
{ | |
[CmdletBinding()] | |
param ( | |
) | |
#define buildin variables | |
$builtinVariable = [PSObject].Assembly.GetType('System.Management.Automation.SpecialVariables').GetFields('NonPublic,Static') | where FieldType -eq ([string]) | foreach GetValue($null) | |
$builtinVariable += @("FormatEnumerationLimit", "MaximumAliasCount", "MaximumDriveCount", "MaximumErrorCount", "MaximumFunctionCount", "MaximumHistoryCount", "MaximumVariableCount", "profile", "psISE", "PSSessionOption", "PSUICulture", "psUnsupportedConsoleApplications", "PSVersionTable", "startupFiles") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Use-NuGetPackage Microsoft.OData.Client -Verbose #Use PSNuGet <https://github.com/altrive/PSNuGet> | |
$context = New-Object Microsoft.OData.Client.DataServiceContext([uri] "https://graph.windows.net") | |
<# | |
New-Object : "1" 個の引数を指定して ".ctor" を呼び出し中に例外が発生しました: "'ClientEdmModelCache' のタイプ初期化子が例外をスローしました。" | |
System.IO.FileNotFoundException: ファイルまたはアセンブリ 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7ce | |
c85d7bea7798e, Retargetable=Yes'、またはその依存関係の 1 つが読み込めませんでした。指定されたファイルが見つかりません。 | |
ファイル名 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' です。'Sys | |
tem.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' |
Add CredentialManager support
It's seems many people creating their own credential management solution.
It's seems, solutions classified 2 types of approach. and there are pros/cons respectively.
- Use OS native Windows Credential Manager(by P/Invoke).
- Persist encrypted credential to file(JSON/XML) under $profile directory.
Please add standard credential management support to PowerShell.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Load NuGet.Core.dll assembly(Load dll as byte stream to avoid dll locking issue) | |
$loadedDll = [AppDomain]::CurrentDomain.GetAssemblies() | where { $_.FullName.StartsWith("NuGet.Core")} | |
if($null -eq $loadedDll) | |
{ | |
$dllPath = Join-Path $PSScriptRoot "NuGet.Core.dll" -Resolve | |
$dllBytes = [IO.File]::ReadAllBytes($dllPath) | |
[System.Reflection.Assembly]::Load($dllBytes) > $null | |
} |