powershell

How to convert an object to a string?

心不动则不痛 提交于 2021-02-17 05:33:25
问题 I want to assign the name of the current directory to construct the path of a parallel directory (to run some diff commands). However when I do this: New-Item -ItemType Directory -Name my_test_dir; Set-Location my_test_dir; $a = $( Get-Item . | Select-Object Name ); write-host( "x${a}x" ); I get x@{Name=my_test_dir}x instead of what I expected : xmy_test_dirx So, how do I "unbox" the name of the directory? PS - for ease of testing I use: mkdir my_test_dir; cd my_test_dir; $a = $( Get-Item . |

Powershell Script Is Not Providing an Output with The Param Function Also Need the Output in an Excel Sheet

浪尽此生 提交于 2021-02-17 05:20:11
问题 What I am trying to achieve is an excel sheet which will contain the list of machines which are not reachable (current output displayed in the image). When I am trying to run the following script with the function, it's not working. How do I get this to work and implement the output into an excel sheet? I realize it's a two part question but I am new to powershell and I really can't figure this out. EDIT: Even after entering a path when the console prompts, nothing happens. OUTPUT: Data Which

bat脚本常用命令

Deadly 提交于 2021-02-17 04:11:20
意气风发啊 骑上我快乐的小摩托 良心公众号啊! 我上墙了 你开始了 嚯嚯嚯嚯嚯 哈哈哈哈哈 皮皮虾我们走 可乐在厨房 红牛在冰箱 6666666 看弹幕,点 关注 " 我相信这不是我一个人的经历:傍晚时分,你坐在屋檐下,看着天慢慢地黑下去,心里寂寞而凄凉,感到自己的生命被剥夺了。当时我是个年轻人,但我害怕这样生活下去,衰老下去。在我看来,这是比死亡更可怕的事。 ——《沉默的大多数》 " title: bat脚本常用命令 date: 2019-11-14 20:23:36 tags: windows script categories: windows script Author:闫玉良 bat 脚本?如果不是从事微软开发相关工作的人员,是不是感觉很耳熟但是又好像不熟悉?还等什么,一睹为快 bat 脚本是 windows 上所用的脚本,我们经常使用的 cmd 一些命令就可以使用。也许你会说为什么不使用 powershell 脚本?因为古老的一些服务器上面没有安装 powershell 你信不信?比如 windows server 2003。 很荣幸,我遇到了,没有什么办法,只能查阅相关资料迎难而上了!脚本其实很简单,下面做一个记录,供大家有需要时获取: 1.设置变量 设置变量使用 SET 关键字,语法如下: SET 变量名=变量值 1. 变量名与变量值一定要紧挨等于号!!!

Using Select-String for checking two .txt files in powershell

a 夏天 提交于 2021-02-17 03:49:02
问题 I am complete new in writting powershell scripts. So far I was using plain batch for my purpose as this is the requirement by my company. Inside this batch I am using nested foor loops to make a comparison of two .txt files, in detail I wantdo do the following: File 1 contains lots of strings. Each string is in one seperate line with a preceded number and semicolon like so: 658;RMS File 2 is some long text. The aim is to count the amount of occurences of each string from File 1 in File 2, e.g

Using Select-String for checking two .txt files in powershell

坚强是说给别人听的谎言 提交于 2021-02-17 03:47:49
问题 I am complete new in writting powershell scripts. So far I was using plain batch for my purpose as this is the requirement by my company. Inside this batch I am using nested foor loops to make a comparison of two .txt files, in detail I wantdo do the following: File 1 contains lots of strings. Each string is in one seperate line with a preceded number and semicolon like so: 658;RMS File 2 is some long text. The aim is to count the amount of occurences of each string from File 1 in File 2, e.g

Get-ADPrincipalGroupMembership Fails when any user group name has “/”

谁说我不能喝 提交于 2021-02-17 03:37:26
问题 This is really annoying and hard to find, but I've proved it in my environment so I thought I'd post it here in hopes of helping more people work around it. The problem is, when using Get-ADPrincipalGroupMembership -Identity $User.SamAccountName and one of their existing group names (that they're a member of) has a / (forward slash) in the name of any one group, it will non-terminate error on that user. So, I ran Get-ADGroup -Filter {name -like "*/*"} to see how many of these groups we have

Get LastAccessTime for each subfolders in a csv folder list

假如想象 提交于 2021-02-17 02:47:51
问题 I have a csv ($HomeDir) file like this: Users,Comments,HomeDir user1,account1,c:\folder1 user2,account2,c:\folder2 user3,account3,c:\folder3 I get succesfully LastAccessTime for each subfolder in 'HomeDir' column with this code: $csv = Import-Csv $HomeDir foreach ($folder in $csv.HomeDir) { Get-ChildItem $folder -ErrorAction SilentlyContinue | ? {$_.PSIsContainer -eq "True"} | Select-Object FullName, @{Name='LastAccessTime'; Expression={$_.LastAccessTime.ToString('yyyyMMdd')}} | Sort-Object

How to pass options to Rundeck job webhook URL

谁说胖子不能爱 提交于 2021-02-17 02:43:21
问题 I have defined a webhook in Rundeck to run a particular job. This job has 3 options defined: ${option.VMName}, ${option.CPU} and ${option.Memory}. The job itself is defined as a local powershell script and executes as: powershell ${scriptfile} ${option.VMName} ${option.CPU} ${option.Memory}. This is tested and works fine. I would now like to invoke the webhook POST URL so that the job is remotely triggered (from a web dashboard, using PowerShell) with these options defined. I tried,

Yaml schema Validation powershell

北战南征 提交于 2021-02-17 00:54:07
问题 I'm working with powershell-yaml to parse my YAML into a PowerShell object. currently, I have a problem validating my YAML schema. I've used this package yaml-schema-validator for my javascript project and I couldn't find any familiar function\moudle to help me solve this problem with Powershell. Is There a schema validation language for YAML in Powershell? 回答1: Simply put, no, I don't believe there are any Powershell native options for doc validation against a YAML schema. Since YAML is a

How does PowerShell treat “.” in paths?

懵懂的女人 提交于 2021-02-16 20:21:27
问题 Consider the following sequence of commands upon opening a PowerShell terminal: PS C:\Users\username> cd source PS C:\Users\username\source> $dir = ".\temp" PS C:\Users\username\source> [System.IO.Path]::GetFullPath($dir) C:\Users\username\temp Now this: PS C:\Users\username> cd source PS C:\Users\username\source> powershell Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved. Try the new cross-platform PowerShell https://aka.ms/pscore6 PS C:\Users\username\source>