FAQ - 7k2mpa/FileMaintenace GitHub Wiki

Can I get result of arcserve UDP backup job?

Product

arcserveUDPbackup.ps1

Answer

You can get the result with arcserve UDP's feature. arcserve UDP can send e-mail error report of job clash or others.

The limitation of arcserve UDP's feature, can not get the result via PowerShell CLI.

Can I run the scripts on PowerShell Core 6.0 or later?

Products

All

Answer

Yes you can. But 'Write-EventLog' cmdlet is removed from PowerShell 6.0 or later, thus you must specify -NoLog2EventLog option.

And default character code of PowerShell 6.0 or later is UTF-8 (ShiftJIS ~Powershell 5.1 in Japanese enviroment) , thus you change character code of the scripts and specify -CommandFileEncode or other encode option to UTF-8.

With -PreAction archive option, can not process the path including a bracket character[

Product

FileMaintenance.ps1

Symptom

With -PreAction archive option and the archived file already existed, archive files and add a file to the file archived, and get an error message blow lines while processing.

発生場所 C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:142 文字:16 + if($item.Attributes.ToString().Contains("ReadOnly")) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) []、RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

Background

Powershell processes asterisk* , question? and bracket[] as a wildcard. Almost cmdlets have -LiteralPath option for processing characters literally but Compress-Archive cmdlet dose not have a Literal option for the destination path. It is a feature, not a bug.
Although with escape character backquote` , can not process the destination path literally.

Solutions

Use 7z compress option.
-PreAction Archive,7z or -PreAction Archive,7zZip
7z can process bracket[] characters literally.

With -PreAction Compress and MoveNewFile and -override options, can not process the path including a bracket character[

Product

FileMaintenance.ps1

Symptom

With -OverRide option and the file already existed, compress a file and override the file existed already, and get an error message blow lines while processing.

+ CategoryInfo : InvalidArgument: (C:\TEST\A[:String) [Compress-Archive]、InvalidOperationException + FullyQualifiedErrorId : ArchiveCmdletPathNotFound,Compress-Archive

Background

Powershell processes asterisk* , question? and bracket[] as a wildcard. Almost cmdlets have -LiteralPath option for processing characters literally but Compress-Archive cmdlet dose not have a Literal option for the destination path. It is a feature, not a bug.
Although with escape character backquote` , can not process the destination path literally.

Solutions

Use 7z compress option.
-PreAction Compress,7z or -PreAction Compress,7zZip
7z can process bracket[] characters literally.

Although I already set execute policy with 'Set-ExecutionPolicy RemoteSigned' and can start Powershell .ps1 scripts and complete successfully on Powershell and ISE window, can not with Hitachi JP1 Automatic Job Scheduler.

Product

All powershell scripts on ~Windows Server 2012R2

Symptom

Background

Powershell includes both 64bit(x64) and 32bit(x86) application. But Hitachi JP1 AJS is a 32bit(x86) application.
Powershell console and ISE run on 64bit by default. Therefore you start Powershell scripts from a Hitachi JP1 AJS's job, the scripts run on 32bit Powershell without setting execute policy.

Solutions

  1. Set execute policy for 32bit Powershell. From Windows Start Menu ,select [Powershell(x86)] and enter 'Set-ExecutionPolicy RemoteSigned'
  2. Start 64bit powershell from 32bit application explicitly.
    Start powershell with path [C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe] instead of [powershell.exe]
    On a JP1 AJS job definition , set
  • 実行ファイル名(Execute Application):C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe
  • パラメータ(Parameter):-Command ".\ChangeIISstate.ps1 -Site SSL -TargetState Running ;exit $LASTEXITCODE" 2>&1
  • ワークパス(current directory):D:\Infra\Scripts\shell

JP1 AJS

Although I can start ChangeIISstate.ps1 and complete successfully on powershell and ISE window, can not with Hitachi JP1 Automatic Job Scheduler.

Product

ChangeIISstate.ps1

Symptom

ChangeIISstate.ps1 With Hitachi JP1 Automatic Job Scheduler, you get error return code and get message blow lines in stdout.

get-website <<<<

`CategoryInfo : NotSpecified: (:) [Get-Website], COMException`
`FullyQualifiedErrorId :`

Background

Powershell includes both 64bit(x64) and 32bit(x86) application. But Hitachi JP1 AJS is a 32bit(x86) application.
Therefore you start ChangeIISstate.ps1 from Hitachi JP1 AJS, ChangeIISstate.ps1 runs on 32bit.
IIS(Internet Information Server) is a 64bit application, and thus you can not use cmdlet such as Get-WebSeite in the script on 32bit powershell.

Solution

Start 64bit powershell from 32bit application explicitly.
Start powershell with path [C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe] instead of [powershell.exe]
On a JP1 AJS job definition , set

  • 実行ファイル名(Execute Application):C:\Windows\Sysnative\WindowsPowerShell\v1.0\powershell.exe
  • パラメータ(Parameter):-Command ".\ChangeIISstate.ps1 -Site SSL -TargetState Running ;exit $LASTEXITCODE" 2>&1
  • ワークパス(current directory):D:\Infra\Scripts\shell

JP1 AJS