FrontPage


ePath `${FlgFile} -Encoding Default\n"@\n\n }\n\n }\n\n return ${SCRVAL}\n\n}\n\n#------------------------------------------------------------------------------\n# 死活確認関数\n#------------------------------------------------------------------------------\n#$AliveStat = Alive_Check sw9000\n#$AliveStat.LogOutput()\n#$AliveStat.AStatus\nfunction Alive_Check(){\n<#\n.SYNOPSIS\n概要\n端末の死活確認\n.DESCRIPTION\n端末の死活確認\n.PARAMETER UnitName\nこのパラメータは<端末名>を指定します。\n.EXAMPLE\nディレクトリを作成する。\n Alive_Check sw9xxx\n#>\n\n [CmdletBinding()]\n [OutputType([String])]\n Param (\n [Parameter(\n HelpMessage="このパラメータは<端末名>を指定します。",\n Mandatory=$true,\n Position=0,\n ValueFromPipeline=$false,\n ValueFromPipelineByPropertyName=$true, \n ValueFromRemainingArguments=$false\n )]\n [String]\n $UnitName\n )\n\n $FQDNName = ${UnitName} + ".mcad.rdh.fujixerox.co.jp"\n $FuncStaTime = Get-Date -format G\n $Msg = @()\n\n try {\n\n $AliveStat = Test-Connection ${FQDNName} -Quiet -count 1\n\n if ( ${AliveStat} -eq ${true} ) {\n\n $Msg += "端末名[${UnitName}]は稼動しているようです。"\n $CMDStat = ${true}\n\n } else {\n\n $Msg += "端末名[${UnitName}]は稼動していないようです。"\n $CMDStat = ${true}\n\n }\n\n } catch {\n\n $Msg += "関数[Alive_Check]予期せぬエラーが発生しました。"\n $CMDStat = ${false}\n foreach( $text in $Error[0] ){ $Msg += $text }\n\n } finally {\n\n $Msg += "関数[Alive_Check]は正常に終了しました。"\n $CMDStat = ${true}\n\n }\n\n # 終了時間セット\n $FuncEndTime = Get-Date -format G\n\n # return用オブジェクトの作成し\n $return = New-Object PSCustomObject\n\n # プロパティ-を設定 \n $return | Add-Member -NotePropertyMembers @{\n Function = "Alive_Check"\n UnitName = ${UnitName}\n Start = ${FuncStaTime}\n End = ${FuncEndTime}\n Message = ${Msg}\n Status = ${CMDStat}\n AStatus = ${AliveStat}\n }\n\n # メソットを定義\n $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n $Func = $this.Function\n $Start = $this.Start\n $UnitName = $this.UnitName\n $Status = $this.Status\n $END = $this.End\n\n if (${Status} -eq ${true}) { $Stat = "Info" }else{ $Stat = "Err" }\n\n # ログ出力フォーマットに変換して出力\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# ${Func}開始 : ${Start}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# UnitName = ${UnitName}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n foreach( $text in $this.Message ){\n msg_output "${Func}" "${Stat}" "# ${text}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n if ($Status -eq $true) {\n\n msg_output "${Func}" "${Stat}" "# ${Func}終了 : ${End}"\n\n }else{\n\n msg_output "${Func}" "${Stat}" "# ${Func}異常 : ${End}"\n\n }\n\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n }\n\n ${return}\n\n}\n\n#------------------------------------------------------------------------------\n# 稼働状況出力関数\n#------------------------------------------------------------------------------\n# \n# \n#\nfunction Operation_Record() {\n\n Param( [string]$UnitName, [string]$username, [string]$JobType )\n\n $RecordTime = Get-Date -format G\n $HostName = hostname\n\n switch (${JobType}) {\n \n "OS" { $JobType = "OS再起動" }\n "SV" { $JobType = "RSGサービス再起動"}\n \n }\n\n $return = "${RecordTime},${HostName},${UnitName},${username},${JobType}"\n\n return ${return}\n\n}\n\n#------------------------------------------------------------------------------\n# ユーザ認証関数\n#------------------------------------------------------------------------------\n# \n# UserAuth $username $password $UnitName\n#\nfunction UserAuth() {\n\n Param( [string]$username, [string]$password, [string]$UnitName )\n\n#------------------------------------------------------------------------------\n# ネットワークドライブ接続\n#------------------------------------------------------------------------------\n $AdmUser = "Administrator"\n $AdmPass = "1!sw-client!1"\n $SecPass = ConvertTo-SecureString ${AdmPass} -AsPlainText -Force\n $cred = New-Object System.Management.Automation.PSCredential(${AdmUser}, ${SecPass})\n #------------------------------------------------------------------------------\n # 利用可能なネットワークドライブの選定\n #------------------------------------------------------------------------------\n [array]$usinglist = Get-PSDrive |%{$_.name}\n [array]$alldrivelist = @("G","H","I","J","K","L","M","N","O","P")\n [array]$availablelist = Compare-Object $alldrivelist $usinglist |?{$_.SideIndicator -match "<="}|%{$_.InputObject}\n $NetDrive = $availablelist[0]\n #------------------------------------------------------------------------------\n $NetPath = "\\${UnitName}.mcad.rdh.fujixerox.co.jp\c`$\fxis"\n\n#----------------------------------------------------------------------\n# ネットワークドライブ接続セクション開始\n#----------------------------------------------------------------------\n\n $FuncStaTime = Get-Date -format G\n $Msg = @()\n\n try {\n\n # ネットワークドライブ接続処理\n $GetPSDrive = Get-PSDrive | Where { $_.Name -eq ${NetDrive} }\n $GetDrive = ${GetPSDrive}.Name\n if ( ${GetDrive} -eq ${NetDrive} ) {\n\n $Msg += "[$DrvName][$NetPath] は既にを接続されていました。"\n $CMDStat = ${true}\n\n } else {\n\n # 認証情報のインスタンスを生成する\n $SecPass = ConvertTo-SecureString ${AdmPass} -AsPlainText -Force\n $cred = New-Object System.Management.Automation.PSCredential(${AdmUser}, ${SecPass})\n\n # ネットワークドライブ接続処理\n $Result = New-PSDrive -name "${NetDrive}" -PSProvider FileSystem -Root "${NetPath}" -Persist -Credential ${cred}\n\n # 接続確認\n $NetDrvStatus = Test-Path ${NetPath}\n \n if ( ${NetDrvStatus} -eq ${true} ) {\n\n $Msg += "[$NetDrive][$NetPath] を接続しました。"\n $CMDStat = ${true}\n\n } else {\n\n $Msg += "[$NetDrive][$NetPath] を接続出来ませんでした。"\n $CMDStat = ${false}\n foreach( $text in $Error[0] ){ $Msg += $text }\n\n }\n\n

}\n\n    } catch {\n\n        $Msg     += &#x22;関数[NetStart]予期せぬエラーが発生しました。&#x22;\n        $CMDStat  = ${false}\n        foreach( $text in $Error[0] ){ $Msg += $text }\n\n    } finally {\n\n        $Msg     += &#x22;関数[NetStart]は正常に終了しました。&#x22;\n        $CMDStat  = ${true}\n\n    }\n\n# 終了時間セット\n    $FuncEndTime = Get-Date -format G\n\n# return用オブジェクトの作成し\n    $return = New-Object PSCustomObject\n\n# プロパティ-を設定 \n    $return | Add-Member -NotePropertyMembers @{\n        Function   = &#x22;UserAuth&#x22;\n        NetDrive   = ${NetDrive}\n        NetPath    = ${NetPath}\n        Start      = ${FuncStaTime}\n        End        = ${FuncEndTime}\n        Message    = ${Msg}\n        Status     = ${CMDStat}\n    }\n\n# メソットを定義\n    $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n        $Func       = $this.Function\n        $Start      = $this.Start\n        $NetDrive   = $this.NetDrive\n        $NetPath    = $this.NetPath\n        $Status     = $this.Status\n        $END        = $this.End\n\n        if (${Status} -eq ${true}) { $Stat = &#x22;Info&#x22; }else{ $Stat = &#x22;Err&#x22; }\n\n        # ログ出力フォーマットに変換して出力\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# NetStart開始 : ${Start}&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# DrvName    = ${NetDrive}&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# NetPath    = ${NetPath}&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        foreach( $text in $this.Message ){\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# ${text}&#x22;\n        }\n        msg_output &#x22;${Func}&#x22; &#x22;$Stat&#x22; &#x22;#--------------------------------------#&#x22;\n        if ($Status -eq $true) {\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# NetStart終了 : ${End}&#x22;\n        }else{\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# NetStart異常 : ${End}&#x22;\n        }\n        msg_output &#x22;${Func}&#x22; &#x22;$Stat&#x22; &#x22;#--------------------------------------#&#x22;\n\n    }\n\n    ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n#----------------------------------------------------------------------\n# ネットワークドライブ接続セクション終了\n#----------------------------------------------------------------------\n\n#----------------------------------------------------------------------\n# ユーザ認証セクション開始\n#----------------------------------------------------------------------\n\n    $Msg                  = @()\n    $FuncStaTime          = Get-Date -format G\n\n    try {\n\n        #----------------------------------------------------------\n        # リモート環境側にスクリプトを作成\n        #----------------------------------------------------------\n\n        $NetDriveNam          = ${NetDrive}\n        $ScriptNam            = &#x22;UserAuthentication.ps1&#x22;\n        $NetScriots           = ${NetDriveNam} + &#x22;:\&#x22; + ${ScriptNam}\n\n        Make_Script UseAuth | Out-File -FilePath ${NetScriots} -Encoding Default -Append\n\n        #----------------------------------------------------------\n        # リモート環境側のローカルパス\n        #----------------------------------------------------------\n        $RemotePath           = &#x22;c:\fxis&#x22;\n        $RemoteScrNam         = Join-Path ${RemotePath} ${ScriptNam}\n\n        #----------------------------------------------------------\n        # リモートコマンド変数作成\n        #----------------------------------------------------------\n        $REMCOM = &#x22;Powershell.exe -ExecutionPolicy ByPass -File ${RemoteScrNam} ${username} ${password} ${UnitName}&#x22;\n        $EXECOM = &#x22;wmic /NODE:${UnitName}.mcad.rdh.fujixerox.co.jp /USER:`&#x22;${AdmUser}`&#x22; /PASSWORD:`&#x22;${AdmPass}`&#x22; process call create `&#x22;${REMCOM}`&#x22;&#x22;\n\n        #----------------------------------------------------------\n        # リモートコマンド実行\n        #----------------------------------------------------------\n        $ErrorActionPreference = &#x22;silentlycontinue&#x22;\n        $EXE = cmd /C &#x22;${EXECOM}&#x22;\n        $ErrorActionPreference = &#x22;continue&#x22;\n\n        Start-Sleep 5\n\n        #----------------------------------------------------------\n        # リモートファイル読み込み\n        #----------------------------------------------------------\n        $NetDriveNam = ${NetDrive}\n        $TextNam     = &#x22;${UnitName}_UserAuthentication.txt&#x22;\n        $NetTextNam  = ${NetDriveNam} + &#x22;:\&#x22; + ${TextNam}\n        $UsrAuthStat = get-content ${NetTextNam}\n\n        #----------------------------------------------------------\n        # スクリプト削除\n        #----------------------------------------------------------\n        remove-item ${NetScriots}\n        remove-item ${NetTextNam}\n\n    } catch {\n\n        $Msg     += &#x22;ユーザ認証が予期せぬエラーが発生しました。&#x22;\n        $CMDStat  = ${false}\n        foreach( $text in $Error[0] ){ $Msg += $text }\n\n    } finally {\n\n        $Msg     += &#x22;ユーザ認証は正常に終了しました。&#x22;\n        $CMDStat  = ${true}\n\n    }\n\n    $FuncStaTime          = Get-Date -format G\n\n# return用オブジェクトの作成し\n    $return = New-Object PSCustomObject\n\n# プロパティ-を設定 \n    $return | Add-Member -NotePropertyMembers @{\n        Function   = &#x22;UserAuth&#x22;\n        Start      = ${FuncStaTime}\n        End        = ${FuncEndTime}\n        Message    = ${Msg}\n        Status     = ${UsrAuthStat}\n    }\n\n# メソットを定義\n    $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n        $Func       = $this.Function\n        $Start      = $this.Start\n        $END        = $this.End\n        $Status     = $this.Status\n\n        if (${Status} -eq ${true}) { $Stat = &#x22;Info&#x22; }else{ $Stat = &#x22;Err&#x22; }\n\n        # ログ出力フォーマットに変換して出力\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# ユーザ認証開始 : ${Start}&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# UserAuth    = ${Status}&#x22;\n        msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;#--------------------------------------#&#x22;\n        foreach( $text in $this.Message ){\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# ${text}&#x22;\n        }\n        msg_output &#x22;${Func}&#x22; &#x22;$Stat&#x22; &#x22;#--------------------------------------#&#x22;\n        if ($Status -eq $true) {\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# ユーザ認証終了 : ${End}&#x22;\n        }else{\n            msg_output &#x22;${Func}&#x22; &#x22;${Stat}&#x22; &#x22;# ユーザ認証異常 : ${End}&#x22;\n        }\n        msg_output &#x22;${Func}&#x22; &#x22;$Stat&#x22; &#x22;#--------------------------------------#&#x22;\n\n    }\n\n    ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n#----------------------------------------------------------------------\n# ユーザ認証セクション終了\n#----------------------------------------------------------------------\n\n#-------------------------------------------------------

taTime}\n End = ${FuncEndTime}\n Message = ${Msg}\n Status = ${CMDStat}\n }\n\n# メソットを定義\n $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n $Func = $this.Function\n $Start = $this.Start\n $NetDrive = $this.NetDrive\n $NetPath = $this.NetPath\n $Status = $this.Status\n $END = $this.End\n\n if (${Status} -eq ${true}) { $Stat = "Info" }else{ $Stat = "Err" }\n\n # ログ出力フォーマットに変換して出力\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# ${JobName}開始 : ${Start}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# DrvName = ${NetDrive}"\n msg_output "${Func}" "${Stat}" "# NetPath = ${NetPath}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n foreach( $text in $this.Message ){\n msg_output "${Func}" "${Stat}" "# ${text}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n if ($Status -eq $true) {\n msg_output "${Func}" "${Stat}" "# ${JobName}終了 : ${End}"\n }else{\n msg_output "${Func}" "${Stat}" "# ${JobName}異常 : ${End}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n }\n\n ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n#----------------------------------------------------------------------\n# ネットワークドライブ接続セクション終了\n#----------------------------------------------------------------------\n\n# ネットワークドライブ接続処理時間調整\nstart-sleep 3\n\n#----------------------------------------------------------------------\n# サービス再起動セクション開始\n#----------------------------------------------------------------------\n\n $Msg = @()\n $FuncStaTime = Get-Date -format G\n $JobName = "サービス再起動"\n\n try {\n\n #----------------------------------------------------------\n # リモート環境側にスクリプトを作成\n #----------------------------------------------------------\n\n $NetDriveNam = ${NetDrive}\n $ScriptNam = "ServiceRestart.ps1"\n $TextNam = "${UnitName}_ServiceRestart.txt"\n $NetScripts = ${NetDriveNam} + ":\" + ${ScriptNam}\n $NetTextNam = ${NetDriveNam} + ":\" + ${TextNam}\n $NetRecText = ${NetDriveNam} + ":\" + ${UnitName} + "_" + ${RecText}\n\n Make_Script SrvRest | Out-File -FilePath ${NetScripts} -Encoding Default\n\n #----------------------------------------------------------\n # リモート環境側のローカルパス\n #----------------------------------------------------------\n $RemotePath = "c:\fxis"\n $RemoteScrNam = Join-Path ${RemotePath} ${ScriptNam}\n\n #----------------------------------------------------------\n # リモートコマンド変数作成\n #----------------------------------------------------------\n $REMCOM = "Powershell.exe -ExecutionPolicy ByPass -File ${RemoteScrNam} ${username} ${password} ${UnitName}"\n $EXECOM = "wmic /NODE:${UnitName}.mcad.rdh.fujixerox.co.jp /USER:`"${AdmUser}`" /PASSWORD:`"${AdmPass}`" process call create `"${REMCOM}`""\n\n #----------------------------------------------------------\n # リモートコマンド実行\n #----------------------------------------------------------\n $ErrorActionPreference = "silentlycontinue"\n $EXE = cmd /C "${EXECOM}"\n $ErrorActionPreference = "continue"\n\n Start-Sleep 3\n\n #----------------------------------------------------------\n # リモートファイル読み込み\n #----------------------------------------------------------\n $SrvResReturn = get-content ${NetTextNam}\n $SrvResStat = @( ${SrvResReturn} -split ',' )\n Operation_Record ${UnitName} ${username} "SV" | Out-File -FilePath ${NetRecText} -Encoding Default -Append\n\n #----------------------------------------------------------\n # スクリプト削除\n #----------------------------------------------------------\n remove-item ${NetScripts}\n remove-item ${NetTextNam}\n\n } catch {\n\n $Msg += "${JobName}で予期せぬエラーが発生しました。"\n $CMDStat = ${false}\n foreach( $text in $Error[0] ){ $Msg += $text }\n\n } finally {\n\n $Msg += "${JobName}は正常に終了しました。"\n $CMDStat = ${true}\n\n }\n\n $FuncEndTime = Get-Date -format G\n\n# return用オブジェクトの作成し\n $return = New-Object PSCustomObject\n\n# プロパティ-を設定 \n $return | Add-Member -NotePropertyMembers @{\n Function = "ServiceRestart"\n Start = ${FuncStaTime}\n End = ${FuncEndTime}\n Message = ${Msg}\n StaTim = (get-date ${SrvResStat}[0]).tostring("yyyy/MM/dd hh:mm:ss")\n EndTim = (get-date ${SrvResStat}[1]).tostring("yyyy/MM/dd hh:mm:ss")\n Status = ${SrvResStat}[3]\n }\n\n# メソットを定義\n $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n $Func = $this.Function\n $Start = $this.Start\n $END = $this.End\n $StaTim = $this.StaTim\n $EndTim = $this.EndTim\n $Status = $this.Status\n\n if (${Status} -eq ${true}) {\n $Stat = "Info"\n }else{\n $Stat = "Err"\n }\n\n # ログ出力フォーマットに変換して出力\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# ${JobName}開始 : ${Start}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# SrvRestart = ${Status}"\n msg_output "${Func}" "${Stat}" "# 再起動前時刻 = ${StaTim}"\n msg_output "${Func}" "${Stat}" "# 再起動後時刻 = ${EndTim}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n foreach( $text in $this.Message ){\n msg_output "${Func}" "${Stat}" "# ${text}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n if ($Status -eq $true) {\n msg_output "${Func}" "${Stat}" "# ${JobName}終了 : ${End}"\n }else{\n msg_output "${Func}" "${Stat}" "# ${JobName}異常 : ${End}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n }\n\n ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n\n#------------------------------------------------------


\n\n# メソットを定義\n $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n $Func = $this.Function\n $Start = $this.Start\n $NetDrive = $this.NetDrive\n $NetPath = $this.NetPath\n $Status = $this.Status\n $END = $this.End\n\n if (${Status} -eq ${true}) { $Stat = "Info" }else{ $Stat = "Err" }\n\n # ログ出力フォーマットに変換して出力\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# ${JobName}開始 : ${Start}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# DrvName = ${NetDrive}"\n msg_output "${Func}" "${Stat}" "# NetPath = ${NetPath}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n foreach( $text in $this.Message ){\n msg_output "${Func}" "${Stat}" "# ${text}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n if ($Status -eq $true) {\n msg_output "${Func}" "${Stat}" "# ${JobName}終了 : ${End}"\n }else{\n msg_output "${Func}" "${Stat}" "# ${JobName}異常 : ${End}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n }\n\n ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n#----------------------------------------------------------------------\n# ネットワークドライブ切断セクション終了\n#----------------------------------------------------------------------\n\n#----------------------------------------------------------------------\n# OS再起動セクション開始\n#----------------------------------------------------------------------\n\n $Msg = @()\n $FuncStaTime = Get-Date -format G\n\n $remote = ${UnitName} + ".mcad.rdh.fujixerox.co.jp"\n $user = ".\administrator"\n $pass = "1!sw-client!1"\n $passwd = ConvertTo-SecureString "${pass}" -AsPlainText -Force\n $credential = New-Object System.Management.Automation.PSCredential(${user}, ${passwd})\n\n try {\n\n Restart-Computer -Force -ComputerName ${remote} -Credential ${credential}\n $CMDStat = ${true}\n\n } catch {\n\n $Msg += "OS再起動で予期せぬエラーが発生しました。"\n $CMDStat = ${false}\n foreach( $text in $Error[0] ){ $Msg += $text }\n\n } finally {\n\n $Msg += "OS再起動を実行しました。"\n $CMDStat = ${true}\n\n }\n\n $FuncEndTime = Get-Date -format G\n\n# return用オブジェクトの作成し\n $return = New-Object PSCustomObject\n\n# プロパティ-を設定 \n $return | Add-Member -NotePropertyMembers @{\n Function = "ServiceRestart"\n Start = ${FuncStaTime}\n End = ${FuncEndTime}\n Message = ${Msg}\n Status = ${CMDStat}\n }\n\n# メソットを定義\n $return | Add-Member -MemberType ScriptMethod -Name LogOutput -Value {\n $Func = $this.Function\n $Start = $this.Start\n $END = $this.End\n $Status = $this.Status\n\n if (${Status} -eq ${true}) {\n $Stat = "Info"\n }else{\n $Stat = "Err"\n }\n\n # ログ出力フォーマットに変換して出力\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# OS再起動 : ${Start}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n msg_output "${Func}" "${Stat}" "# OS Restart = ${Status}"\n msg_output "${Func}" "${Stat}" "#--------------------------------------#"\n foreach( $text in $this.Message ){\n msg_output "${Func}" "${Stat}" "# ${text}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n if ($Status -eq $true) {\n msg_output "${Func}" "${Stat}" "# OS再起動終了 : ${End}"\n }else{\n msg_output "${Func}" "${Stat}" "# OS再起動異常 : ${End}"\n }\n msg_output "${Func}" "$Stat" "#--------------------------------------#"\n\n }\n\n ${return}.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n#----------------------------------------------------------------------\n# OS再起動セクション終了\n#----------------------------------------------------------------------\n\n}\n\n#------------------------------------------------------------------------------\n# 入力項目端末名のチェック関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction host_check() {\n\n Param( [string]$Lo_Host )\n\n $Lo_Stat = ${false}\n $Lo_HostChk = [int]${Lo_Host}.length\n\n # ホスト名の文字数確認\n # 以下のコメントは本関数のバリデーション状況\n # Sw9000 6 Sw true \n # SW9000 6 SW true \n # Sw8999 6 Sw true \n # SW8999 6 SW true \n # sWmC9000 8 sWmC true \n # sWm99000 8 sWm9 false\n # swMC0000 8 swMC true \n # SWmc0000 8 SWmc true \n # SWcm0000 8 SWcm false\n # mc0000 6 mc false\n # mcsw0000 8 mcsw false\n # cmws0000 8 cmws false\n # cwms0000 8 cwms false\n # scwm0000 8 scwm false\n # 00000000 8 0000 false\n # 000000 6 00 false\n\n if ( ${Lo_HostChk} -eq 8 ) {\n $Lo_SubStr = ${Lo_Host}.Substring(0,4)\n if ( ${Lo_SubStr} -match "[Ss][Ww][Mm][Cc]" ) { $Lo_Stat = ${true} }\n } elseif ( ${Lo_HostChk} -eq 6 ) {\n $Lo_SubStr = ${Lo_Host}.Substring(0,2)\n if ( ${Lo_SubStr} -match "[Ss][Ww]" ) { $Lo_Stat = ${true} }\n }\n\n if ( $Lo_Stat -eq ${true} ) { $Lo_HostStat = ${true} } else { $Lo_HostStat = ${false} }\n\n return ${Lo_HostStat}\n\n}\n\n#------------------------------------------------------------------------------\n# 入力項目ユーザIDチェック関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction user_check() {\n\n Param( [string]$Lo_User )\n\n $Lo_User = $Lo_User.trim()\n\n\n if ( ( ${Lo_User} -eq $null ) -Or ( ${Lo_User}.Length -eq 0 ) ) { $Lo_UserStat = "False" } else { $Lo_UserStat = "True" }\n return ${Lo_UserStat}\n\n}\n\n#------------------------------------------------------------------------------\n# 入力項目パスワードチェック関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction pass_check() {\n\n Param( [string]$Lo_Pass )\n\n if ( ( ${Lo_Pass} -eq $null ) -Or ( ${Lo_Pass}.Length -eq 0 ) -Or ( ${Lo_Pass}.trim() -eq "" ) ) { $Lo_PassStat = "False" } else { $Lo_PassStat = "True" }\n return ${Lo_PassStat}\n\n}\n\n#------------------------------------------------------------------------------\n# 入力項目チェック関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction input_check() {\n\n Param( [string]$Lo_Host, [string]$Lo_User, [string]$Lo_Pass )\n\n $MSG = $ null\n $Cnt = [int]0\n\n $Lo_HostStat = host_check ${Lo_Host}\n $Lo_UserStat = user_check ${Lo_User}\n $Lo_PassStat = pass_check ${Lo_Pass}\n\n $MSG = "以下の入力内容に誤りがあります。`n"\n $MSG += "`n" \n\n # 入力内容チェック\n if ( ${Lo_HostStat} -eq ${false} ) {\n\n $Cnt = [int]${Cnt} + 1\n $MSG += "端末名(${Lo_Host})に誤りがあります。`n"\n\n }\n\n if ( ${Lo_UserStat} -eq ${false} ) {\n\n $Cnt = [int]${Cnt} + 1\n $MSG += "ユーザIDに誤りがあるようです。`n"\n\n }\n\n if ( ${Lo_PassStat} -eq ${false} ) {\n\n $Cnt = [int]${Cnt} + 1\n $MSG += "パスワードに誤りがあるようです。`n"\n\n }\n\n if ( ${Cnt} -eq 0 ) {\n\n $Stat = "True"\n\n } else {\n\n $Stat = "False"\n $MSG += "`n" \n $MSG += "処理を中止します。`n"\n $MSG += "`n"\n\n }\n\n $Reslut = @( "${Stat}" , "${MSG}" )\n\n return ${Reslut}\n\n}\n\n#------------------------------------------------------------------------------\n# メッセージ関連関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction form_msg_setting () {\n\n Param( [string]$Key, [string]$Srv )\n\n switch (${Srv}) {\n "Os" { $Srv = "OS" }\n "Sv" { $Srv = "RGS サービス" }\n }\n\n switch (${Key}) {\n\n "INIT" {\n $MSG = "端末名・ユーザID・パスワードをご入力ください。`n"\n }\n\n "EXECHK" {\n $MSG = "${Srv}の再起動処理を実行されますか?`n"\n $MSG += "`n"\n $MSG += "ご入力いただいた内容は以下の通りです。`n"\n $MSG += "`n"\n $MSG += " 端末名  :${Lo_Host}`n"\n $MSG += " ユーザID :${Lo_User}`n"\n $MSG += "`n"\n $MSG += "よろしければ「はい」を押下ください。`n"\n }\n\n "OSCHK" {\n $MSG = "端末名 ${Lo_Host} のOS稼動確認を実施しています。`n"\n $MSG += "`n" \n $MSG += "しばらくお待ちください。`n"\n }\n\n "OSCHKSUC" {\n $MSG = "端末名 ${Lo_Host} は稼動しています。`n"\n $MSG += "`n" \n $MSG += "ユーザ認証をおこないます。`n" \n $MSG += "`n" \n $MSG += "しばらくお待ちください。`n"\n }\n\n "OSCHKERR" {\n $MSG = "選択された端末名は 「 ${Lo_Host} 」稼動していないようです。`n"\n $MSG += "`n"\n $MSG += "処理を中止します。`n"\n }\n\n "USRCHK" {\n $MSG = "ユーザ認証中です。`n"\n $MSG += "`n" \n $MSG += "認証ユーザは ${Lo_User} です。`n" \n $MSG += "`n" \n $MSG += "しばらくお待ちください。`n"\n }\n\n "USRCHKSUC" {\n $MSG = "ユーザ認証に成功しました。`n"\n $MSG += "`n" \n $MSG += "${Srv}の再起動を実施します。`n" \n $MSG += "`n" \n $MSG += "しばらくお待ちください。`n"\n }\n\n "USRCHKERR" {\n $MSG = "ユーザ認証に失敗しました。`n"\n $MSG += "`n"\n $MSG += "${Srv}の再起動を中止します。`n" \n $MSG += "`n"\n $MSG += "以下の入力内容に問題があるようです。`n"\n $MSG += "`n"\n $MSG += "入力内容:`n"\n $MSG += " 端末名  :${Lo_Host}`n"\n $MSG += " ユーザID :${Lo_User}`n"\n $MSG += "`n"\n $MSG += "もう一度初めから実行してください。`n"\n }\n\n "REBSUC" {\n $MSG = "${Srv}の再起動を実施しました。`n"\n $MSG += "`n"\n $MSG += "1分後に再度接続してください。`n"\n }\n\n "CANWAY" {\n $MSG = "${Srv}の再起動処理を中止しました。`n"\n $MSG += "`n"\n }\n\n "CANCEL" {\n $MSG = "処理を中止します。`n"\n }\n \n }\n\n return ${MSG}\n\n}\n\n#------------------------------------------------------------------------------\n# ボタン押下後処理関数\n#------------------------------------------------------------------------------\n#\n#\n#\n#\nfunction click() {\n\n Param( [string]$But )\n\n $Lo_Host = ($UnitName_Text.Text).Trim()\n $Lo_User = ($UserName_Text.Text).Trim()\n $Lo_Pass = ($UserPass_Text.Text).Trim()\n $Sleep = [int]15\n\n if ( -not( $But -eq "Vw" ) ) {\n\n # 入力内容チェック\n $Input = ( input_check ${Lo_Host} ${Lo_User} ${Lo_Pass} ) -split ","\n\n $MSG = $Input[1]\n\n if ( $Input[0] -eq ${false} ) {\n\n $But = $null\n\n }\n\n }\n\n switch (${But}) {\n\n "Vw" {\n\n $MSG = form_msg_setting "CANCEL"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n# Start-Sleep -s ${Sleep}\n foreach ($MSL in ${MSG}) { msg_output "${But}" "Info" ${MSL} | Out-File -FilePath ${SCRLOG} -Encoding Default -Append }\n\n }\n\n {($_ -eq "Os" ) -or ( $_ -eq "Sv")} {\n \n $MSG = form_msg_setting "EXECHK" "${But}"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n $result = [System.Windows.Forms.MessageBox]::Show("${MSG}" , "確認" , "YesNo" , "Question" , "Button2" )\n\n #結果表示\n If($result -eq "Yes"){\n\n $MSG = form_msg_setting "OSCHK"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n\n $Alive = Alive_Check ${Lo_Host}\n $Alive.LogOutput() | Out-File -FilePath ${SCRLOG} -Encoding Default -Append\n\n if ( $Alive.AStatus -eq ${true} ){\n\n $MSG = form_msg_setting "OSCHKSUC"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n Start-Sleep -s ${Sleep}\n\n $MSG = form_msg_setting "USRCHK"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n\n # ユーザ認証\n $UserStatus = ( UserAuth "${Lo_User}" "${Lo_Pass}" "${Lo_Host}" )\n\n if( ${UserStatus} -eq ${true} ) {\n\n #------------------------------------------------------\n # ユーザ認証に問題があった状態\n #------------------------------------------------------\n $MSG = form_msg_setting "USRCHKSUC" "${But}"\n $ExecStat_Lbl.Text = "${MSG}"\n $Form.Refresh()\n\n if ( $

     # 行番号\n        $RowInd                       = ${RowNum} - 1\n        $UnitTop                      = ( ${Base_Top} * ${RowNum} ) + ( ${Base_Ind} * ${RowInd} )\n\n        $UnitLab_v_x                  = [int]( ${Base_Lef} + ${Base_Lbl_W} + ${Base_Txt_W} + ( ${Base_Ind} * 3 ) )\n        $UnitLab_v_y                  = [int]${UnitTop}\n        $UnitLab_o_x                  = [int]${Base_But_W}\n        $UnitLab_o_y                  = [int]${Base_But_H}\n        $view                         = @(${UnitLab_v_x}&#x2c;${UnitLab_v_y}&#x2c;${UnitLab_o_x}&#x2c;${UnitLab_o_y})\n\n        $ButSvRes                     = New-Object System.Windows.Forms.Button\n        $ButSvRes.Location            = New-Object System.Drawing.Point(${view}[0]&#x2c;${view}[1])\n        $ButSvRes.Size                = New-Object System.Drawing.Size(${view}[2]&#x2c;${view}[3])\n        $ButSvRes.Text                = &#x22;RGSサービス再起動&#x22;\n#        $ButOsRes.DialogResult        = &#x22;OK&#x22;\n        $ButSvRes.Flatstyle           = &#x22;Popup&#x22;\n\n        $Form.Controls.Add($ButSvRes)\n\n       # サービス再起動ボタン表示位置調整\n        $RowNum                       = 2\n        $RowInd                       = ${RowNum} - 1\n        $UNamTop                      = ( ${Base_Top} * ${RowNum} ) + ( ${Base_Ind} * ${RowInd} )\n\n        $UNamLab_v_x                  = [int]( ${Base_Lef} + ${Base_Lbl_W} + ${Base_Txt_W} + ( ${Base_Ind} * 3 ) )\n        $UNamLab_v_y                  = [int]${UNamTop}\n        $UNamLab_o_x                  = [int]${Base_But_W} # 固定値 オブジェクトの横幅\n        $UNamLab_o_y                  = [int]${Base_But_H} # 固定値 オブジェクトの高さ\n        $view                         = @(${UNamLab_v_x}&#x2c;${UNamLab_v_y}&#x2c;${UNamLab_o_x}&#x2c;${UNamLab_o_y})\n\n        $ButOsRes                     = New-Object System.Windows.Forms.Button\n        $ButOsRes.Location            = New-Object System.Drawing.Point(${view}[0]&#x2c;${view}[1])\n        $ButOsRes.Size                = New-Object System.Drawing.Size(${view}[2]&#x2c;${view}[3])\n        $ButOsRes.Text                = &#x22;OS再起動&#x22;\n #       $ButSvRes.DialogResult        = &#x22;OK&#x22;\n        $ButOsRes.Flatstyle           = &#x22;Popup&#x22;\n\n        $Form.Controls.Add($ButOsRes)\n\n       # キャンセルボタン表示位置調整\n        $RowNum                       = 3\n        $RowInd                       = ${RowNum} - 1\n        $UPasTop                      = ( ${Base_Top} * ${RowNum} ) + ( ${Base_Ind} * ${RowInd} )\n\n        $UPasLab_v_x                  = [int]( ${Base_Lef} + ${Base_Lbl_W} + ${Base_Txt_W} + ( ${Base_Ind} * 3 ) )\n        $UPasLab_v_y                  = [int]${UPasTop}\n        $UPasLab_o_x                  = [int]${Base_But_W}    # 固定値 オブジェクトの横幅\n        $UPasLab_o_y                  = [int]${Base_But_H}    # 固定値 オブジェクトの高さ\n        $view                         = @(${UPasLab_v_x}&#x2c;${UPasLab_v_y}&#x2c;${UPasLab_o_x}&#x2c;${UPasLab_o_y})\n\n        $ButVwCan                     = New-Object System.Windows.Forms.Button\n        $ButVwCan.Location            = New-Object System.Drawing.Point(${view}[0]&#x2c;${view}[1])\n        $ButVwCan.Size                = New-Object System.Drawing.Size(${view}[2]&#x2c;${view}[3])\n        $ButVwCan.Text                = &#x22;終了&#x22;\n        $ButVwCan.DialogResult        = &#x22;Cancel&#x22;\n        $ButVwCan.Flatstyle           = &#x22;Popup&#x22;\n\n        $Form.Controls.Add($ButVwCan)\n\n    #------------------------------------------------------------------------------\n    # 実行ステータス表示\n    #------------------------------------------------------------------------------\n\n        # ヘッダー\n        $RowNum                       = 4\n        $RowInd                       = ${RowNum} - 1\n        $UPasTop                      = ( ${Base_Top} * ${RowNum} ) + ( ${Base_Ind} * ${RowInd} )\n\n        $UPasLab_v_x                  = [int]${Base_Lef}\n        $UPasLab_v_y                  = [int]${UPasTop}\n        $UPasLab_o_x                  = [int]375\n        $UPasLab_o_y                  = [int]220\n        $view                         = @(${UPasLab_v_x}&#x2c;${UPasLab_v_y}&#x2c;${UPasLab_o_x}&#x2c;${UPasLab_o_y})\n\n        $GpBox                        = New-Object System.Windows.Forms.GroupBox\n        $GpBox.Location               = New-Object System.Drawing.Point(${view}[0]&#x2c;${view}[1])\n        $GpBox.size                   = New-Object System.Drawing.Size(${view}[2]&#x2c;${view}[3])\n        $GpBox.text                   = &#x22;Status&#x22;\n\n        # 出力欄\n        $RowNum                       = 4\n        $RowInd                       = ${RowNum} - 1\n        $UPasTop                      = ${Base_Top}\n\n        $UPasLab_v_x                  = [int]${Base_Lef}\n        $UPasLab_v_y                  = [int]${UPasTop}\n        $UPasLab_o_x                  = [int]325\n        $UPasLab_o_y                  = [int]185\n        $view                         = @(${UPasLab_v_x}&#x2c;${UPasLab_v_y}&#x2c;${UPasLab_o_x}&#x2c;${UPasLab_o_y})\n\n        $ExecStat_Lbl                 = New-Object System.Windows.Forms.Label\n        $ExecStat_Lbl.Location        = New-Object System.Drawing.Point(${view}[0]&#x2c;${view}[1])\n        $ExecStat_Lbl.Size            = New-Object System.Drawing.Size(${view}[2]&#x2c;${view}[3])\n        $ExecStat_Lbl.Text            = form_msg_setting &#x22;INIT&#x22;\n        $ExecStat_Lbl.TextAlign       = &#x22;TopLeft&#x22;\n        $ExecStat_Lbl.Font            = $Font10\n#        $ExecStat_Lbl.BorderStyle     = &#x22;FixedSingle&#x22;\n\n        $GpBox.Controls.AddRange(@(${ExecStat_Lbl}))\n        $Form.Controls.AddRange(@($GpBox))\n\n    #------------------------------------------------------------------------------\n    # 画面表示\n    #------------------------------------------------------------------------------\n\n        $ButOsRes.Add_Click({ click(&#x22;OS&#x22;) })\n        $ButSvRes.Add_Click({ click(&#x22;Sv&#x22;) })\n        $ButVwCan.Add_Click({ click(&#x22;Vw&#x22;) })\n\n        $Result = $form.ShowDialog()\n\n}\n\n#------------------------------------------------------------------------------\n# ユーザフォーム呼び出し\n#------------------------------------------------------------------------------\n\n$LOGPATH = (Convert-Path .)\n$SCRLOG  = &#x22;${LOGPATH}\reboot_tool.log&#x22;\n$RecText = &#x22;SuperRebootMan_OperationRecord.txt&#x22;\n\nmsg_output &#x22;msg_output&#x22; &#x22;Info&#x22; &#x22;ログファイルを初期化します。&#x22; | Out-File -FilePath ${SCRLOG} -Encoding Default\n\nassenbli_load System.Windows.Forms\nassenbli_load System.Drawing\n\nUser_Form\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nplay.pp987654@gmail.com&#x2c;pl@y0123\nplay.pp012345@gmail.com&#x2c;pl@y0123\nplay.pp220511@gmail.com&#x2c;pl@y0123)

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS