Jump to content


radish

ps script locate _SMSTSLogPath variable output problem

Recommended Posts

I have a copy item copy script running the output log under windows platform to _SMSTSLogPath. The output log cannot be set successfully. I tried to fail. What should I do?

$start = Get-Date
Function Import-SMSTSENV{
   
        $tsenv = New-Object -COMObject Microsoft.SMS.TSEnvironment
        $TSEnv.Value("_SMSTSLogPath")
        # Create an object to access the task sequence environment
#$tsenv = New-Object -ComObject Microsoft.SMS.TSEnvironment

# Query the environment to get an existing variable
# Set a variable for the task sequence log path
$LogPath = $tsenv.Value("_SMSTSLogPath")
    
        }


#创建日志文件名称
$detetetime = (get-date -format "yyyy年MM月dd日HH时MM分ss秒") 
$applicationlog = "$detetetime" + "HD Tune Pro v5.70 v2 免注册汉化版单文件.log"
$applicationlog
#启动powershell控制台日志记录

Start-transcript -path $LogPath\"$applicationlog"
#Start-transcript -path $env:temp\"$applicationlog"
#<#


#>
#当前目录
#$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
 
#获取脚本运行所在目录
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent 

#判断操作系统32位以及64位的Program Files目录Program Files (x86),并根据操作系统位数输出目录
$application = (${env:ProgramFiles(x86)}, ${env:ProgramFiles} -ne $null)[0]

#变量赋值自定义文件夹如:在"Program Files 或 (Program Files x86)" 路径里创建一个 "HD Tune Pro v5.70 v2 免注册汉化版单文件" 文件夹
$application2 = "HD Tune Pro v5.70 v2 免注册汉化版单文件"  

#变量赋值自定义快捷方式桌面快捷方式名称如:HDTunePro_Win8_10
$lnkshortcutname = "HDTunePro_Win8_10" 


#变量赋值自定义原始程序名称如:HDTunePro_Win8_10.exe
$lnkshortcutname2 = "HDTunePro_Win8_10.exe" 

#变量赋值自定义文件夹路径如:C:\Program Files\HD Tune Pro v5.70 v2 免注册汉化版单文件
$newapplication = "$application\$application2"

#变量赋值自定义快捷方式桌面路径如:C:\Program Files\HD Tune Pro v5.70 v2\HDTunePro_Win8_10.exe
$lnknewapplication = "$application\$application2\$lnkshortcutname2"


#判断文件夹名是否存在并创建文件夹
if(-not (Test-Path $newapplication)){
        mkdir "$newapplication" | Out-file $env:temp"\"'$applicationlog'
    }

#判断powershell运行x86 x64版本    
$newPSVersion = if ([IntPtr]::Size -eq 8){
    'x64'
}
else
{
    'x86'
}         

#查询时间
$datetime = get-date -format "yyyy年MM月dd日HH:MM:ss" 
#当前区域语言
$LANG = (Get-Culture).Name
#查询操作系统名称以及位数
$ws = (Get-WmiObject Win32_OperatingSystem).osarchitecture 
$OS = (Get-WmiObject -Class Win32_OperatingSystem).Caption
#查询IP相关信息
$wmi = Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'true'"
$ipwgdef = $wmi.DefaultIPGateway 
$ipdizhi = (ipconfig|select-string "IPv4"|out-string).Split(":")[-1].trim() -replace(" |`t|\r|\`n ,``")  
$ipyanma = (ipconfig|select-string "子网掩码"|out-string).Split(":")[-1].trim() -replace(" |`t|\r|\`n ,``")    

#$ARCHITECTURE = $env:PROCESSOR_ARCHITECTURE

#获取PS脚本文件名
$ScriptName = $MyInvocation.MyCommand.Name

#系统信息输出显示powershell窗口
Write-Output ""
Write-Output "$ScriptName - 当前时间:$datetime"
Write-Output "$ScriptName - 用  户名: $env:USERNAME"
Write-Output "$ScriptName - 计算机名: $env:COMPUTERNAME"
Write-Output "$ScriptName - IP  地址: $ipdizhi"
Write-Output "$ScriptName - 网    关: $ipwgdef"
Write-Output "$ScriptName - IP  掩码: $ipyanma"
Write-Output "$ScriptName - 当前域名: $env:USERDNSDOMAIN"
Write-Output "$ScriptName - 源  路径: $executingScriptDirectory"
Write-Output "$ScriptName - 目的路径:$newapplication"
Write-Output "$ScriptName - 操作系统: $OS $ws "
Write-Output "$ScriptName - 当前语言: $LANG "
Write-Output "$ScriptName - PSVersion:$newPSVersion $($PSVersionTable.PSVersion.tostring())"


#开始复制文件,并排除复制指定Copy20200315.ps1脚本文件
Get-ChildItem -Path "$executingScriptDirectory" -Exclude "*.ps1" | Copy-Item -Recurse -Destination "$newapplication" 

#(Get-ChildItem -Path "$executingScriptDirectory" -Exclude "*.ps1" | Copy-Item -Recurse -Destination "$newapplication" -verbose 4>&1).Message  

   
#开始创建快捷键图标步骤
$shortcut_name = "$lnkshortcutname"    #快捷键图标名称
$shortcut_target = "$lnknewapplication" #设置快捷键桌面图标路径
$sh = new-object -com "WScript.Shell"
$p = $sh.SpecialFolders.item("AllUsersDesktop") #设置到   All\Users\Desktop\   桌面路径
$lnk = $sh.CreateShortcut( (join-path $p $shortcut_name) + ".lnk" )
$lnk.TargetPath = $shortcut_target
$lnk.IconLocation = "$lnknewapplication" #设置快捷键桌面图标ICO
$lnk.Save()


$end = Get-Date
#脚本总运行时间
Write-Host ('Total Runtime: ' + ($end - $start).TotalSeconds)秒


Start-Sleep -s 60
#停止powershell控制台日志
Stop-transcript

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.