POWERSHELLパワーシェル関数

本ページには広告が含まれています。

POWERSHELLを実行します。UWSCのPOWERSHELL関数は呼び出すたびに時間が掛るため、この起動時間を改善したPowerShell (自作関数)を使います。

構文
  1. UString = POWERSHELL( コマンド, 同期フラグ, 画面表示 )
引数
コマンド (String)必須
POWERSHELLのコマンド
同期フラグ (Boolean = False)省略可
FALSE
終了を待つ (デフォルト)
TRUE
待たずに戻る
画面表示 (Boolean = False)省略可
FALSE
POWERSHELL画面を表示しない (デフォルト)
TRUE
表示する
2
最小化状態で起動する
戻り値
標準出力を返す(同期フラグがTrue、もしくは画面表示がTrue,2の場合は返しません)

プログラム実行例

ファイルの作成日時・更新日時・アクセス日時を書き換える

UWSC
DIM FSO = CREATEOLEOBJ("Scripting.FileSystemObject")

DIM path = "D:\Documents\sample.txt"
DIM folderspec = FSO.GetParentFolderName(path)
DIM filename = FSO.GetFileName(path)
DIM CreationTime = "2022/07/01 00:00:00"      // 作成日時
DIM LastWriteTime = "2022/07/01 00:00:00"     // 更新日時
DIM LastAccessTime = "2022/07/01 00:00:00"    // アクセス日時

PRINT POWERSHELL("pushd <#DBL>" + folderspec + "<#DBL>;" + _
                    "Set-ItemProperty " + filename + " -name CreationTime -value  <#DBL>" + CreationTime + "<#DBL>;" + _
                    "Set-ItemProperty " + filename + " -name LastWriteTime -value  <#DBL>" + LastWriteTime + "<#DBL>;" + _
                    "Set-ItemProperty " + filename + " -name LastAccessTime -value  <#DBL>" + LastAccessTime + "<#DBL>;" + _
)
使用関数

PCをシャットダウンする(PowerShell)

PowerShellのStop-ComputerコマンドでPCのシャットダウンを行います。

UWSC
POWERSHELL("Stop-Computer -Force")
使用関数
解説

PCを再起動する(PowerShell)

PowerShellのRestart-Computer コマンドでPCの再起動を行います。

UWSC
POWERSHELL("Restart-Computer -Force")
使用関数
解説

システムの起動時間を取得

システムの起動時間をyyyy年m月d日 h:n:sの形式で取得します。

UWSC
PRINT TRIM(POWERSHELL("[Management.ManagementDateTimeConverter]::ToDateTime((Get-WmiObject Win32_OperatingSystem).LastBootUpTime)"))
結果
プレーンテキスト
2019年12月21日 15:53:56
使用関数

IEオブジェクト(COMオブジェクト)のメンバー一覧を取得する

UWSC
PRINT POWERSHELL("$ie = New-Object -ComObject InternetExplorer.Application;Get-Member -InputObject $ie")
結果
プレーンテキスト


   TypeName: System.__ComObject#{d30c1661-cdaf-11d0-8a3e-00c04fc9e26e}

Name                 MemberType Definition                                                  
----                 ---------- ----------                                                  
ClientToWindow       Method     void ClientToWindow (int, int)                              
ExecWB               Method     void ExecWB (OLECMDID, OLECMDEXECOPT, Variant, Variant)     
GetProperty          Method     Variant GetProperty (string)                                
GoBack               Method     void GoBack ()                                              
GoForward            Method     void GoForward ()                                           
GoHome               Method     void GoHome ()                                              
GoSearch             Method     void GoSearch ()                                            
Navigate             Method     void Navigate (string, Variant, Variant, Variant, Variant)  
Navigate2            Method     void Navigate2 (Variant, Variant, Variant, Variant, Variant)
PutProperty          Method     void PutProperty (string, Variant)                          
QueryStatusWB        Method     OLECMDF QueryStatusWB (OLECMDID)                            
Quit                 Method     void Quit ()                                                
Refresh              Method     void Refresh ()                                             
Refresh2             Method     void Refresh2 (Variant)                                     
ShowBrowserBar       Method     void ShowBrowserBar (Variant, Variant, Variant)             
Stop                 Method     void Stop ()                                                
AddressBar           Property   bool AddressBar () {get} {set}                              
Application          Property   IDispatch Application () {get}                              
Busy                 Property   bool Busy () {get}                                          
Container            Property   IDispatch Container () {get}                                
Document             Property   IDispatch Document () {get}                                 
FullName             Property   string FullName () {get}                                    
FullScreen           Property   bool FullScreen () {get} {set}                              
Height               Property   int Height () {get} {set}                                   
HWND                 Property   int HWND () {get}                                           
Left                 Property   int Left () {get} {set}                                     
LocationName         Property   string LocationName () {get}                                
LocationURL          Property   string LocationURL () {get}                                 
MenuBar              Property   bool MenuBar () {get} {set}                                 
Name                 Property   string Name () {get}                                        
Offline              Property   bool Offline () {get} {set}                                 
Parent               Property   IDispatch Parent () {get}                                   
Path                 Property   string Path () {get}                                        
ReadyState           Property   tagREADYSTATE ReadyState () {get}                           
RegisterAsBrowser    Property   bool RegisterAsBrowser () {get} {set}                       
RegisterAsDropTarget Property   bool RegisterAsDropTarget () {get} {set}                    
Resizable            Property   bool Resizable () {get} {set}                               
Silent               Property   bool Silent () {get} {set}                                  
StatusBar            Property   bool StatusBar () {get} {set}                               
StatusText           Property   string StatusText () {get} {set}                            
TheaterMode          Property   bool TheaterMode () {get} {set}                             
ToolBar              Property   int ToolBar () {get} {set}                                  
Top                  Property   int Top () {get} {set}                                      
TopLevelContainer    Property   bool TopLevelContainer () {get}                             
Type                 Property   string Type () {get}                                        
Visible              Property   bool Visible () {get} {set}                                 
Width                Property   int Width () {get} {set}
使用関数

Shellオブジェクト(COMオブジェクト)のメンバー一覧を取得する

UWSC
PRINT POWERSHELL("$shell = New-Object -ComObject Shell.Application;Get-Member -InputObject $shell")
結果
プレーンテキスト


   TypeName: System.__ComObject#{286e6f1b-7113-4355-9562-96b7e9d64c54}

Name                 MemberType Definition                                                    
----                 ---------- ----------                                                    
AddToRecent          Method     void AddToRecent (Variant, string)                            
BrowseForFolder      Method     Folder BrowseForFolder (int, string, int, Variant)            
CanStartStopService  Method     Variant CanStartStopService (string)                          
CascadeWindows       Method     void CascadeWindows ()                                        
ControlPanelItem     Method     void ControlPanelItem (string)                                
EjectPC              Method     void EjectPC ()                                               
Explore              Method     void Explore (Variant)                                        
ExplorerPolicy       Method     Variant ExplorerPolicy (string)                               
FileRun              Method     void FileRun ()                                               
FindComputer         Method     void FindComputer ()                                          
FindFiles            Method     void FindFiles ()                                             
FindPrinter          Method     void FindPrinter (string, string, string)                     
GetSetting           Method     bool GetSetting (int)                                         
GetSystemInformation Method     Variant GetSystemInformation (string)                         
Help                 Method     void Help ()                                                  
IsRestricted         Method     int IsRestricted (string, string)                             
IsServiceRunning     Method     Variant IsServiceRunning (string)                             
MinimizeAll          Method     void MinimizeAll ()                                           
NameSpace            Method     Folder NameSpace (Variant)                                    
Open                 Method     void Open (Variant)                                           
RefreshMenu          Method     void RefreshMenu ()                                           
SearchCommand        Method     void SearchCommand ()                                         
ServiceStart         Method     Variant ServiceStart (string, Variant)                        
ServiceStop          Method     Variant ServiceStop (string, Variant)                         
SetTime              Method     void SetTime ()                                               
ShellExecute         Method     void ShellExecute (string, Variant, Variant, Variant, Variant)
ShowBrowserBar       Method     Variant ShowBrowserBar (string, Variant)                      
ShutdownWindows      Method     void ShutdownWindows ()                                       
Suspend              Method     void Suspend ()                                               
TileHorizontally     Method     void TileHorizontally ()                                      
TileVertically       Method     void TileVertically ()                                        
ToggleDesktop        Method     void ToggleDesktop ()                                         
TrayProperties       Method     void TrayProperties ()                                        
UndoMinimizeALL      Method     void UndoMinimizeALL ()                                       
Windows              Method     IDispatch Windows ()                                          
WindowsSecurity      Method     void WindowsSecurity ()                                       
WindowSwitcher       Method     void WindowSwitcher ()                                        
Application          Property   IDispatch Application () {get}                                
Parent               Property   IDispatch Parent () {get}
使用関数

関連記事

DOSCMD関数 (スクリプト関数)
コマンドプロンプトを実行します。
POFF関数 (スクリプト関数)
電源断、ログオフなどの操作をします。
FolderItem.InvokeVerb メソッド (Shell)
ファイルやフォルダを右クリックしたときに表示されるメニューのコマンドを実行します。