#get_dir.ps1
$FilePath = "C:\Users\Admin\cred.sec"
$Username = "Admin"
$result = Test-Path $FilePath
if(!($result)){
$msgBoxInput = [System.Windows.MessageBox]::Show('[.sec]ファイルが見当たりません。credential.ps1を実行しますか?いいえを選択するとスクリプトが終了します。','実行確認','YesNo','Question')
switch ($msgBoxInput) {
'Yes' {
\\fsv01\sv01\powershell\credential.ps1
}
'No' {
[System.Windows.Forms.MessageBox]::Show("スクリプトを終了します。.secファイルを作成してから再度実行してください。","結果","OK","Exclamation")
exit
}
}
}
$fsv = "\\fsv01\sv01"
#ユーザー名とパスワードを暗号化したファイルを読み込み
$encryptedCred = Get-Content $FilePath | ConvertTo-SecureString
#クレデンシャル(PsCredential)を生成
$cred = New-Object System.management.Automation.PsCredential($Username, $encryptedCred)
net use $fsv /user:$username $cred.getnetworkcredential().password
$arr_str = cmd /c dir /-c $fsv | findstr "バイトの空き領域"
$a = $arr_str.Split(" ")
$b = $a[18]
$c = [long]$b
$c.GetType()
if ($c.gettype().name -eq "Int64"){
Write-Host "OK"
}else{
Write-Host "NG"
}
$g = [Math]::Round($c/2948501864448*100, 2, [MidpointRounding]::AwayFromZero);
"空き容量" + [string]$g + "%"
$f = $c*2007
$f
net use $fsv /delete /y