
Powershell
mystert
这个作者很懒,什么都没留下…
展开
-
Powershell 每页拆分PDF Split PDF In Page
参考资料:https://stackoverflow.com/questions/18762007/split-pdf-into-multiple-pdfs-using-itextsharp参考是基于Vb.net, 本文改为Powershell吐槽:老外是真的狗,明明人家都问怎么只拆分前8页,拆分步骤都有了,但是下面的答案几乎各种乱七八糟。。。,其实加个判断PDF是否多于8页,如果多于8页,循环就拆前8页就好,如果少于8页,全拆就好了。直接上代码:[void][System.Reflecti原创 2021-07-08 23:01:17 · 383 阅读 · 0 评论 -
Powershell “Column Number“ to Letter(数字转英文字母)
直接上代码:function ColumnLetter(){ param([System.Int32]$ColumnNumber) $n = $ColumnNumber; do{ $c = (($n - 1) % 26); $s = [System.Char]::ConvertFromUtf32($c + 65) + $s; #$n = (n - $c) \ 26 $n = (($n - $c) - (...原创 2021-06-28 23:35:53 · 293 阅读 · 0 评论 -
Powershell 字典Dictionary嵌套列表List 详解
字典可以有很多个keyword, 每一个字典都可以放到列表:这边是一个列子:[System.Collections.Generic.List[Object]]$mList = @{};[System.Collections.Generic.Dictionary[String,Object]]$mDic = @{};$mDic["day"] = "0900";$mDic["night"] = "2100";$mList.Add($mDic);$mDic["day"] = "1100原创 2021-06-28 23:35:21 · 2262 阅读 · 0 评论 -
Powershell 浅谈正则表达式贪婪与非贪婪
今天写正则表达式发现$Matches = [System.Text.RegularExpressions.Regex]::Matches("客户人数:10","客户人数.*(\d{1,3})")仅能匹配 0(目标是获取10) :查了下百度发现默认是贪婪模式,也就是尽可能获取更多的字符,这边 \d{1,3} 是获取数字1到3位的意思,那么前面的 .* 是可以把1也占为己有了可见贪婪模式不是一般的贪,为了避免他贪污我们后面的数字,我们需要用 .*? 防止他贪了我们后面的 \d{...原创 2021-03-15 23:51:10 · 386 阅读 · 1 评论 -
Powershell 浅谈创建List类型
通常创建List:这时候的myList是空白的,但是如果创建的时候等于{}:这时候的myList是有内容的,只不过这个内容是空白的字符:这个时候如果我们使用类似 $myList -join "," 的时候就会出现第一个index是空白字符串的情况了。举一反三:创建Collection的时候如果等于{}的时候也是会有内容的总结:在Powershell创建类似Collection, List等类型的时候要等于@(),不要直接等于{}...原创 2021-02-03 21:25:37 · 2296 阅读 · 0 评论 -
Powershell Bug(Contains),能用indexof的最好不要用contains
今天发现发现字符串contains的BUG。。。。(/泪目),毕竟我的项目都写了好多contains....其实就是比较$sAttFileName_Lower是否包含$sStaffName,大小写我已经全部转为小写,但是$sAttFileName_Lower居然不包含"jennie zhou":但是当我写"jennie zhou"居然是True:然后我比较了一下$sStaffName -eq"jennie zhou", 居然是一样的。。。。最后我发现...原创 2021-02-03 21:24:41 · 450 阅读 · 1 评论 -
Powershell Read DataTable
$In_dtInOak = [System.Data.DataTable]::new();# Add Column Name$xlApp = New-Object -ComObject Excel.Application;$xlApp.visible = $true;$xlBook = $xlApp.Workbooks.Open("C:\Users\XXX.xlsx");$xlSheet = $xlBook.Worksheets.Item(1);$cMax = $xlSheet.Us原创 2020-11-19 22:38:14 · 271 阅读 · 0 评论 -
Powershell 拆分和合并PDF
这里使用到 itextsharp dll, 需要的可以在我的优快云下载:$dllpath = "\\cnfuoapp130\rpa_folder\kdc_rpa\Jayden\RC_Expense\Rc_Submit_IBS\Library";$sourcePDF = "C:\Users\jtang20\Desktop\splitPdf\20200912_SLE-BEL-S-20-003_Rachel Zheng12345678.pdf";$outputFolder = $s...原创 2020-11-15 10:27:26 · 746 阅读 · 0 评论 -
Powershell Create DataTable(创建数据表)
$In_dtInOak = [System.Data.DataTable]::new();$ret = $In_dtInOak.Columns.Add("C_KEY");$ret = $In_dtInOak.Columns.Add("CONTENT");$ret = $In_dtInOak.Columns.Add("LEVEL");$xlApp = New-Object -ComObject Excel.Application;$xlBook = $xlApp.Workbooks.Ope原创 2020-08-22 14:53:05 · 726 阅读 · 0 评论 -
Powershell 正则 日期 其他
首先说一下日期,对于匹配2020.02.03, 2020/02/03, 02/03/2020 02.03.2020可以使用$strDate -match "(\d{2}[\/\.]){2}\d{4}" -or $strDate -match "\d{4}([\/\.]\d{2}){2}"[\/\.]是匹配 .或者/的意思类似Java 7 Update 17Java(TM) 6 Update 25Java(TM) 6 Update 27Java(TM) 6 Update 25.原创 2020-07-05 22:28:21 · 375 阅读 · 0 评论 -
Powershell 获取Outlook Email Information
$AliasName = "Zhao, Janice (KDC/HR)";$matches = [System.Text.RegularExpressions.Regex]::Matches($AliasName, "(\w+)\,\s(\w+)\s");$first = $matches[0].Groups[2].Value;$last = $matches[0].Groups[1].Value;$outlookApp = New-Object -ComObject Outlook.App原创 2020-06-29 23:49:34 · 945 阅读 · 0 评论 -
Powershell 关于识别某个单元格是否日期格式
直接上代码:if($sht.range("A1").value().gettype() -eq [System.DataTime]){ write-host "Type : Data Time"}else{ write-host "Type : Not Data Time"}原创 2020-06-29 23:50:07 · 335 阅读 · 0 评论 -
Powershell Filter FileName
$path = "\\cnfuofsr50.cn.kworld.kpmg.com\fs\Audit\Special\Audit RPA\UiPath developer\SNS\To-do\Final declaration review";$curList = Get-ChildItem -Path $path -Filter "for RPA to do list*" | Sort-Object LastWriteTime -Descending | Select-Object -First 1;.原创 2020-06-07 10:58:30 · 288 阅读 · 0 评论 -
Uipath/Powershell Uipath传入Powershell DataRows
因为Uipath调用Powershell的时候不能传入System.Collections.Generic.IEnumerable<System.String>,可以把它转换为数组:Powershell:原创 2020-06-07 10:57:58 · 439 阅读 · 0 评论 -
Uipath/Powershell 获取Split最后值
Uipath:system.DateTime.ParseExact(r("Send Email Day(L1)").ToString.Split({";"}, StringSplitOptions.None).Last,"yyyy-MM-dd HH:mm:ss",Nothing){";"}是数组的意思Powershell:同理@(",")也是是数组的意思[System.StringSplitOptions]::RemoveEmptyEntries表示如果碰到空白的..原创 2020-06-07 10:56:08 · 1278 阅读 · 0 评论 -
Powershell/Vba 关于Filter的行必须大于1行
如果不判断行数是否大于一行,直接排序,当行数只有一行(标题)的时候,保存的EXCEL会报错正确写法:原创 2020-06-07 10:53:04 · 334 阅读 · 0 评论 -
Uipath调用Powershell Script 存在中文问题
如果Powershell Scipt里面存在中文,单独运行Powershell 是没有问题的,但是如果用Uipath调用的,会出现Error:但是大部分时间还是可以通过的,如果不通过,我们可以根据实际情况考虑,因为我这个workbook只有一个sheet,那么我们可以这样:...原创 2020-06-07 10:48:30 · 441 阅读 · 0 评论 -
Powershell删除含文件或文件夹的文件夹
当使用Powershell Remove-Item删除一个目录的时候,如果目录存在文件或者文件夹:这时候会弹出Error询问:这是因为目录有文件的时候不能直接删除目录,这里我们可以加上参数Recurse:Remove-Item -Path "C:\Users\jtang20\Desktop\BeDeletedFolder" -Recurse这样我们删除目录...原创 2020-02-11 19:10:10 · 14041 阅读 · 0 评论 -
2020-01-22 Powershell 移动MAIL技巧
今天主要想说下移动MAIL的一些技巧,因为在符合某些条件的时候一封MAIL要从一个邮箱的INBOX移动到其他目录,这是INBOX的总邮件数是会减少一封的,所以在写For的时候,判断结束条件$j -le $AllMailItem.count的$AllMailItem.count一定不能定义为$AllMailItem.count,要先定义为一个变量,因为$AllMailItem.count是会变的,导...原创 2020-01-31 17:43:53 · 311 阅读 · 0 评论 -
2020-01-17 Powershell 打开一个EXE
需要全路径Invoke-Item -Path "C:\Program Files (x86)\Microsoft Office\Office15\Excel.exe"原创 2020-01-31 17:42:40 · 905 阅读 · 0 评论 -
2020-01-16 Powershell Find&FindNext 改自Vba
这里以找出重复数最大行为列子:Function FindMaxRow(){ param( $sht, $Column, $sTemp ) $findResult = $sht.columns($Column).Find($sTemp,[System.Type]::Missing,[System.Type]::...原创 2020-01-31 17:42:18 · 306 阅读 · 0 评论 -
Uipath/Powershell 详细介绍DataRow
读取Excel的DataRows 或者 DataRow访问对应的列:Uipath:#assign 所有行myDataRows =dt.Rows.Cast(Of System.Data.DataRow).Where(Function(r) r("Item - KTL").ToString = "离职证明")#write-line 拿出第一行的第一列的值myDataRo...原创 2020-01-30 18:27:18 · 3010 阅读 · 0 评论 -
Powershell 正则匹配
$AliasName = "Zhao, Janice (KDC/HR)";$matches = [System.Text.RegularExpressions.Regex]::Matches($AliasName, "(\w+)\,\s(\w+)\s");$first = $matches[0].Groups[2].Value;$last = $matches[0].Groups[1]...原创 2020-01-30 18:26:43 · 1127 阅读 · 0 评论 -
Powershell RTF(Rich Text) Mail Body Insert File
$xlOutlook = New-Object -ComObject Outlook.Application;$olMailItem = $xlOutlook.CreateItem(0);$olMailItem.BodyFormat = 3;$olMailItem.Body = “Hello, Jayden.`n`n`n`n`n`n`ntxtFilePos`nThis is an sa...原创 2020-01-30 16:12:22 · 305 阅读 · 1 评论 -
Powershell Outlook 获取当前打开的Mail
$xlOutlook = New-Object -ComObject Outlook.Application;$openMail = $xlOutlook.Inspectors[1].CurrentItem;write-host $openMail.Subject;$xlOutlook = $null;$olMailItem = $null;[GC]::Collect();原创 2020-01-30 16:11:30 · 413 阅读 · 0 评论 -
Powershell Excel 复制上面单元格FormulaLocal
因为公司封了博客园和优快云,GIT HUB,今天开始入驻简书,废话不多说,今日分享Powershell关于公式:通常我们前面的单元格有公式的时候:可以看到单元格"L143"有公式,那么当我们想"L144"也有同样的公式:$sht_Booking_Month_Details.range("L" + $iRowCount_Details).FormulaLocal = $sh...原创 2020-01-30 16:11:15 · 539 阅读 · 0 评论 -
(Bug)Powershell outlook check name获取邮箱地址
https://blog.youkuaiyun.com/Q215046120/article/details/90400630的方法存在BUG在Telephone Directory搜索这里一堆人找不到EMAIL ADDRESS原创 2020-01-29 22:06:06 · 351 阅读 · 0 评论 -
Powershell/Vba 查看AddressEntry.AddressEntryUserType
Sub ResolveDisplayNameToSMTP()Dim oRecip As Outlook.RecipientDim oEU As Outlook.ExchangeUserDim oEDL As Outlook.ExchangeDistributionListDim xloutlook As Outlook.ApplicationSet xloutlook = Ne...原创 2020-01-29 22:05:25 · 263 阅读 · 0 评论 -
Powershell Excel Find各种参数
在EXCEL中:Powershell是这样的:$sht.find($sTargetValue,[System.Type]::Missing,[System.Type]::Missing,1);最后的参数1 是 xlwhole的值原创 2020-01-29 22:04:48 · 472 阅读 · 0 评论 -
Powershell itextSharp PDF打中文水印
## PDF Add WaterMark[void][System.Reflection.Assembly]::LoadFile($itextSharpDllPath);$pdfReader = [iTextSharp.text.pdf.PdfReader]::new($sOriPdfPath);$stream = [System.IO.FileStream]::new($sTempW...原创 2020-01-29 22:03:02 · 295 阅读 · 0 评论 -
Uipath Import EPPlus
如果发现Uipath 的Imports里面没有OfficeOpenXml,可以在Manage Package里面找Epplus或者KDCExcel导入后就可以在Invoke Code引用ExcelPackage原创 2020-01-29 21:36:20 · 324 阅读 · 0 评论 -
PowerShell/VBA Outlook排序邮件并获取第一封
https://stackoverflow.com/questions/78924/when-is-a-mailitem-not-a-mailitemPowershell$xlOutlook = New-Object -ComObject Outlook.Application;$NS = $xlOutlook.Session.Application.GetNamespace("MAP...原创 2020-01-29 21:35:30 · 894 阅读 · 0 评论 -
Powershell Outlook 获取当前打开的Mail
$xlOutlook = New-Object -ComObject Outlook.Application;$openMail = $xlOutlook.Inspectors[1].CurrentItem;write-host $openMail.Subject;$xlOutlook = $null;$olMailItem = $null;[GC]::Collect();原创 2020-01-29 19:24:25 · 438 阅读 · 0 评论 -
Powershell改vb code写法(遍历文件夹下所有文件)
原Powershell写法:$pList = Get-ChildItem -Path $sFolderPath -Recurse;foreach ($sFile in $pList){ Write-Host $sFile.FullName;}改为vb code:Dim sFile As StringFor Each sFile In system.IO.Directo...原创 2019-10-25 11:41:33 · 271 阅读 · 0 评论 -
PowerShell自动加载账号密码(Credential)
大家在使用PowerShell时,经常会遇到输入账号密码的问题,如下图特别是执行一些循环操作的时候,每次都手动输入账号密码,特别不爽,研究发现,嵌入以下代码,能解决此问题此例子的账号为:Demo\User01,密码为:Password,注:密码一定要符合复杂度要求。$User = "Demo\User01"$PassWord = ConvertTo-SecureString ...转载 2019-10-21 17:11:06 · 1938 阅读 · 0 评论 -
Powershell itextSharp PDF打中文水印
上次写的帖子因为在打印中文的时候会出现问题:(Powershell itextSharp PDF打水印)https://blog.youkuaiyun.com/Q215046120/article/details/101203225这里参考了http://www.cc.ntu.edu.tw/chinese/epaper/0015/20101220_1509.htmhttp://www.blue...原创 2019-10-21 12:18:28 · 332 阅读 · 0 评论 -
Powershell 中文转UNICODE
直接上CODE:$str = "我是谁"$ustr = ""for($i = 0; $i -lt $str.Length; $i++){ if([int]$str[$i] -gt 32 -and [int]$str[$i] -lt 127){ $ustr += $str[$i] } else{ $ustr += [System.St...原创 2019-10-21 12:12:29 · 1186 阅读 · 0 评论 -
Powershell 数字转大写中文,数字金额转中文繁体(改自C#)
改自原创C#语法:https://zhidao.baidu.com/question/587949259275229805.html?fr=iks&word=c%23+%CA%FD%D7%D6+%D6%D0%CE%C4&ie=gbk直接上代码:Function MoneyConvertChinese($LowerMoney){ [string]$func...转载 2019-10-16 14:18:55 · 694 阅读 · 0 评论 -
Powershell 获取某文件路径作为文件对象
例如桌面下存在文件"1.txt"直接上Code:$sFilePath = "$env:USERPROFILE\Desktop\1.txt";$file = [io.fileinfo]$sFilePath;# 文件目录write-host ($file.DirectoryName);# 全文件名write-host ($file.Name);# 纯文件名write-host ...原创 2019-08-28 17:22:01 · 2950 阅读 · 0 评论 -
Powershell/Vba 关于打开Excel时出现We can't update some of the links in your workbook
我们通过Powershell 或者 Vba打开Excel时,有时候会出现如下这种框:还有一种框是updateXXX link,这种框跟上述图片一样,都是为了提示用户EXCEL里面有公式,但是对于Script并不友好,我们可以使用Code解决:Powershell 写法:在打开Excel Path写一句$xlapp.application.AskToUpdateLinks = $fa...原创 2019-07-12 16:09:58 · 1449 阅读 · 0 评论