PowerShell バックアップ(曜日ごとフォルダ分け)

 

PowerShell ユーザー名、IPアドレスをメールする

 

PowerShell UWPアプリのショートカット作成

Win+R>shell:AppsFolder>右クリック>ショートカットの作成
が一番簡単。

・手動で作成したい場合①

直接実行ファイルからショートカットを作成する。

実行ファイルはプログラムを起動して
Win+R>taskmgr>ファイルの場所を開く
から調べられる。

・手動で作成したい場合②

explorer shell:AppsFolder\[AUMID]
このような感じでショートカットを作成する。

AUMID (Application User Model ID)取得方法いくつか

個別に取得(2つを!でつなげる)

現在のユーザーのみ

別のユーザー1

別のユーザー2(書き方が違うだけ)

 

PowerShell テキストファイル1行ごと数値チェック

 

PowerShell ~$ファイル(Excel)移動

 

PowerShell 繰返しping

 

PowerShell リモート接続設定

ホスト側のPC

enable-psremoting
を実行。

ネットワークがPublicだと接続できない。
Win10の設定>ネットワークとインターネット>接続プロパティの変更>プライベート

接続できるユーザを追加。
Set-PSSessionConfiguration -Name Microsoft.PowerShell -showSecurityDescriptorUI
追加するとき、もしMicrosoftアカウントならメールアドレスで検索して追加。

クライアント側のPC

クライアント側から信頼できるホストを追加。
Set-Item WSMan:\localhost\Client\TrustedHosts -Value PC_name

接続は、
Enter-PSSession -ComputerName PC_name -Credential mail@xxx.com
を実行。

切断は、
Exit-PSSession

エイリアス追加

必要なら
Set-ExecutionPolicy Unrestricted

$profile
を実行すると読み込まれているかどうか分かる。

既にファイルが存在すれば、
notepad $profile
存在しなければ、
New-item -type file -force $profile
notepad $profile
を実行し、以下のように記述。

Set-Alias -name c -value cd
Set-Alias -name l -value ls
Set-Alias -name pss -value f
function f()
{
Enter-PSSession -ComputerName PC_name -Credential mail@xxx.com
}

PowerShell 特定日数後アラート

PowerShell 初期設定

管理者権限でPowerShellを起動

・実行ポリシー確認
Get-ExecutionPolicy

・実行ポリシー
Set-ExecutionPolicy RemoteSigned

Restricted:実行不可
AllSigned:署名付きスクリプトのみ実行可
RemoteSigned:ローカル+ダウンロードした署名付きスクリプトのみ実行可
Unrestricted:すべてのスクリプト実行可

次に、
New-Item registry::HKEY_CLASSES_ROOT\Microsoft.PowerShellScript.1\shell\open\command -value ‘”C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe” “& ”%1””‘ -force
を実行。