FAQ Database Discussion Community
powershell
We need to extract a report every month for our servers which should report who all are having the server admin access .This will help us remove the people for whom access is no more needed. Its taking lot of time to extract manually and I read on blogs that...
sql-server,sql-server-2008,powershell
Background: I have a directory with a number of files that are imported to SQL server. Task: Creating a PowerShell script which will pick up files within this directory and use the filenames as in the SQL query. Ultimate objective: To display SQL results besides the filenames but the resultset...
powershell,tcm
I try to get a list of all my TestSuites of a specific TestPlan with PowerShell and TCM.exe by writing: $listOfSuites = & "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\TCM.exe" suites /list /planid:1234 I get the right result, but it is formated as a single String like: Id Name --------- ----------------------------------------------------------------...
email,powershell,foreach
I am trying to write a script to search through AD and look for any stale computers and then sends an email to me. However, there are 3 requirements: get the lastlogondate for any pc that is older than 90 days once I get that list, I do a ping...
powershell,powershell-v3.0
Let's assume that you have a command that compresses files using 7-zip that accepts values from the pipeline: Function New-Archive { [CmdletBinding()] param ( [Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelineByPropertyName=$True)][Alias('FullName')] [string[]]$Files, [string]$Archive='Archive.zip' ) BEGIN {} PROCESS { Foreach ($File in $Files) { & 7z a -tZIP $Archive $File } } END {} } Assuming the...
powershell
I'm looking over a block of code I've used (sourced from another question) and I haven't been able to figure out what the . in .{process represents in this snippet (comments removed): Get-ItemProperty $path | .{process{ if ($_.DisplayName -and $_.UninstallString) { $_ } }} | Select-Object DisplayName, Publisher, InstallDate, DisplayVersion,...
visual-studio,powershell,nuget,tabexpansion
This is a script for VS PowerShell. function global:Add-Shape { param([string]$Shape, [string[]]$Colors) Write-Host "Shape Name:$Shape" foreach ($i in $Colors) { Write-Host "Color Name:$i" } } Register-TabExpansion 'Add-Shape' @{ 'Shape' = { "Circle", "Square", "Triangle" } 'Colors' = { "Brown", "Red", "Blue" } } In Package Manager Console When I try...
powershell,cmdlet,chocolatey
How do I add dynamic argument tab completion to a PowerShell Cmdlet? When I type this and hit tab, I'd like for it to do tab completion. PM> Paket-Add -NuGet FSharp.Co These are the values I'd like to use in this example: PM> Paket-FindPackages -SearchText FSharp.Co FSharp.Core FSharp.Core.3 FSharp.Configuration FSharp.Core.Fluent-3.1...
powershell,ip-address,gateway
I've a project to add persistent routes on a list of servers which I need to do through Powershell. Our environment has 2 NIC's for every server , one production one backup. For this I need to fetch the Backup IP address of the computer , replace the last octet...
xml,powershell
I'm having trouble getting a properly formatted XML file using the following code: # Get Computer System info $CompInfo = Get-WmiObject Win32_ComputerSystem $CompName = $CompInfo.Name # Get IP Address $IPAddressTemp = Test-Connection $CompName -count 1 | select Address,Ipv4Address $IPAddress = $IPAddressTemp.IPV4Address # Begin Writing values to XML Document $filePath =...
powershell,credentials,start-process
I'm running into a strange behavior with a powershell Start-Process call. Here is the call: $process = start-process ` "C:\somepath\MyBinary.exe" ` -PassThru ` -Credential $defaultCredential ` -Wait ` -WorkingDirectory "C:\somepath" ` -LoadUserProfile if ($process.ExitCode -ne 0) { #do something } This call always return with the exit code -1073741502. After...
powershell,active-directory,user,organization,ou
I am trying to get a script to work that will organize my active directory accounts based off of their display name since all of our accounts have their OU in their name (or a subOU). I am trying to do this with an If statement inside of a ForEach...
.net,powershell,f#,system.reactive,f#-async
There is a subscription to an observable that sends out log messages. Some of the log messages come from other threads because they are are in F# async blocks. I need to be able to write out the messages from the main thread. Here is the code that currently filters...
regex,powershell
I need to search though a folder of logs and retrieve the most recent logs. Then I need to filter each log, pull out the relevant information and save to another file. The problem is the regular expression I use to filter the log is dropping the carriage return and...
powershell,arguments,transformation,credentials,invoke-command
I'm trying to run a powershell invoke-command call with a PSCredential as parameter. But the call fails with the error: Invoke-Command : Cannot process argument transformation on parameter 'Credential'. userName" Here is the detailed output I get : error 17-Jun-2015 14:33:53 Invoke-Command : Cannot process argument transformation on parameter 'Credential'....
powershell,iis,octopus-deploy
We use OctopusDeploy to create the website and we use the create website template that is on the community step sites. I have modified it slightly to ensure that if the website exists it adds the default binding however it is removing all the existing bindings. Is there a way...
powershell,registry
I'm not sure why I'm finding this so difficult. From under a particular registry key, I'd like to query certain registry-values based on their data (not name), and delete the resulting registry-values. For example: How would I delete any values in this key that contain, let's say, "foo". I can...
excel,powershell
How can I close a specific Excel workbook in PowerShell? I have a script that opens 4 CSV files and an XLS file and manipulates some data. I am having a problem closing the CSV files and leaving the XLS file open. I have tried $xl.workbooks.close() but that closes everything....
powershell,hyper-v,sccm
I am trying to write a script that will take the hyper-V host as an input as well as the search string for the list of VM's I want to move...this is all via SCCM VMM, and its all 2012R2 Here is what I have so far... $VMHOST = read-host...
windows,git,powershell,github,github-for-windows
After installing GitHub for Windows, I can use git command in Powershell directly: C:\Users\xiaona\Documents\GitHub> git usage: git [--version] [--help] [-C <path>] [-c name=value] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path] [-p|--paginate|--no-pager] [--no-replace-objects] [--bare] [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>] <command> [<args>] The most commonly used git commands are: add Add file contents to the index bisect...
windows,powershell,command-line,exif,exiftool
I am using ExifTool to change the camera body serial number to be a unique serial number for each image in a group of images numbering several hundred. The camera body serial number is being used as a second place, in addition to where the serial number for the image...
powershell,active-directory,user,rename,identity
This morning some awesome people helped me make a script to move user accounts based on their displayName to a certain OU. I tested and it worked. I cannibalized the script to make another one that will rename the same accounts based off of the same criteria. I've gone through...
powershell,powershell-v4.0
The script is comparing folder names in a share where we store user profiles to those in AD and seeing which ones are disabled or don't exist and counting them. I now want to take that list and rename all the user folders that aren't in AD to .old. $delusercount...
powershell,filesize,get-childitem
I need to copy files to a folder until they exceed a specified size. I've written the following script but it fails with the following error: Cannot compare "Microsoft.PowerShell.Commands.GenericMeasureInfo" because it is not IComparable. At C:\33.ps1:8 char:1 + "{0:N2}" -f ($colItems.sum / 1024MB) $files = Get-ChildItem C:\source -Recurse | %...
powershell,if-statement
When using Test-Path in an if statement, I am looking to get the path that the if statement succeeds with. For example, these files exist in C: C:\Test6_1_15.txt C:\Test6_2_15.txt C:\Test6_3_15.txt C:\Test6_4_15.txt what do I do in the "then" branch? $Path = "C:\Test6_*_15.txt" if (Test-Path $Path) { # if test passes...
windows,git,powershell,github,go
I try to use go get gopkg.in/fatih/pool.v2 to install pool according to Readme.md, but can't success: C:\Users\xiaona\Documents\GitHub> go get -v gopkg.in/fatih/pool.v2 Fetching https://gopkg.in/fatih/pool.v2?go-get=1 https fetch failed. Fetching http://gopkg.in/fatih/pool.v2?go-get=1 import "gopkg.in/fatih/pool.v2": http/https fetch: Get http://gopkg.in/fatih/poo l.v2?go-get=1: dial tcp 107.178.216.236:80: ConnectEx tcp: A connection attempt failed because the connected party did not...
excel,powershell,automation,system32,syswow64
NOTE: I am on a 64-bit system. I am having trouble finding articles regarding my current situation. I using PowerShell to test if a certain path exists: "C:\Windows\SysWOW64\config\systemprofile\Desktop" and it returns true even though the Desktop folder does not exist in SysWOW64. I know it is related to the fact...
regex,powershell
I have a Powershell file myfile.ps1: function Do-It { $items = # A command that returns a collection of strings like: # Element 12657 - <Description trext> # Element 12656 - <Description trext> # Element 12655 - <Description trext> # ... $pattern = 'Element\s(\d*).*'; foreach ($item in $items) { $res...
powershell,automation,error-logging
I have a script here that reads a list of computers and changes the administrator password. When the script is ran, it'll have a log file that says whether the task succeeded or fail. But I also want to log the actual error to the log when it fails. How...
c#,powershell
I'm trying to run a PowerShell script from C# code, but I'm having some (maybe environmental) issues: On a machine where I try to run it, the following occur: PowerShell starts and loads as Admin PowerShell window immediately closes (apparently) without error Notes: The script works. When I run it...
powershell,iis
I am trying to update Enable Parent Paths = True of ASP Application in IIS for all available websites by Power Shell Script. Below is my power shell script which I tried but it works for Specific Website only. Set-WebConfigurationProperty ` -PSPath MACHINE/WEBROOT/APPHOST ` -Location 'Default Web Site' ` -Filter...
powershell,powershell-v2.0
I have some video files and some subtitle files. There is a common part in the name of each of them, for example *E05*.srt and *E05*.mkv. I'd like to rename each video file to match its subtitle, without .srt of curse. Can you think of any script for that? I...
variables,powershell,powershell-v2.0
I got two variables, filled with: $Var1: Dog Cat Bird $Var2: makes wau makes miau makes beep How can I mix both of them like: $Var3 Dog makes wau Cat makes miau Bird makes beep $Var3 = $Var1 + $Var2 dosen't work...
powershell
The script below is excellent but I am unable to figure out how to assign it to a string that can be used as the body of an email. Can someone help a newbie on this one? #Requires -Version 2.0 Function Get-LockedOutLocation { <# .SYNOPSIS This function will locate the...
powershell,workflow
I am trying to restart Windows services in parallel via Powershell workflow. When I use Get-Service -DisplayName "S*" outside of workflow I get expected results. However, when I use the same in workflow, I get ALL services instead. It seems that -Displayname parameter is ignored in workflow. How do I...
powershell,azure,azure-active-directory
I am attempting to setup an Azure AD application to authenticate using a certificate. I have been using this guide to successfully set this up after failing following this guide. I wish to now automate the process so it can be added to our general build scripts, looking at the...
powershell,nuget-package
I have a nuget spec that installs both library file (dll) and two zip packages on a specific folder. Updating the packages is no issue when doing it from Visual Studio 2013 manually. However, when it is being triggered from either our CI servers TeamCity and CCNet, it is only...
powershell,get-childitem
I am using Get-ChildItem to fetch locally installed certs. Then I'd like to delete these certs from my local certificate store. If I execute the script below it will work when there is more than one item returned in both the Get-ChildItem queries. But if only one item is returned...
powershell,active-directory
I have some powershell script which gets the owner of certain files like so: $CreationOwner =Get-Acl $path | Select-Object Owner but now I have the AD name like so domain\ar is there anyway to now turn this into the name of the person...
html,powershell,powershell-v5.0
I have been running a password expiration script for the pass 6 months without any issue. The script will read in a static html file and change around some of the content in memory and then an html email will be sent to all users who have expiring passwords. The...
powershell
I have a file that contains the date it was created in the file name: 2456Backup20150615.txt I would like to be able to grab that file name and create a new blank text file with the same name and add the extension .pgp.trg: 2456Backup20150615.txt.pgp.trg Is there anyway that that can...
powershell
I need to pass an array to a PowerShell subprocess and was wondering how I can turn an environment variable (string) into a PowerShell array. Is there a convention I need to follow so PowerShell will do it for me automatically or I just need to parse it myself? I'm...
powershell,batch-file,registry,windows-7-x64,regedit
I'm writing a script (powershell) for SQL Server 2014 Express Install. The problem is: I have to change the OS Language (Region and languages) to fr_FR (French from France) Silently. The current language is fr_CA (French from Canada). My question is: Can i change the language from intl.cpl (Region and...
powershell
I would like to open a C:\Program Files\R\R-3.2.0\bin\Rscript.exe. For that I am trying to change the directory. I figured that the error is in opening Program files. Following is the code cd Program Files\R\R-3.2.0\bin Error: A positional parameter cannot be found that accepts argument Files ...
arrays,powershell
From this I can see I can do this with range operator: $myArray = @(4..9) But how can I do something like this: $myArray = @(usr4..9) I have tried various deviations of this with nonsense errors: $myArray = 4..9 | %\{ "usr$_"\} ...
powershell
I'm trying to write a powershell instance that finds and replaces each instance of text and replaces it. UserRights "rights_wo_view" I need to place parenthesis around the quotes. I've been trying all kinds of things, but I'm running flat. $files = get-item C:\Users\programmer\Documents\Project\tsbrick\*.asp foreach ($file in $files) {(Get-Content $file) select-string...
powershell,parameter-passing
& "$THIS_SCRIPTS_DIRECTORY_PATH\New-NuGetPackage.ps1" -PushOptions "$pushOptions" ` -Verbose -ProjectFilePath $project -PO "$packOptions" -NPFPPTNG So if I provide the command line above in PowerShell the call works correctly. If I try something like this: if ($NoPromptForPushPackageToNuGetGallery) { $xtraOptions += " -NPFPPTNG " } & "$THIS_SCRIPTS_DIRECTORY_PATH\New-NuGetPackage.ps1" -PushOptions "$pushOptions" ` -Verbose -ProjectFilePath $project -PO "$packOptions"...
c#,.net,powershell,tfs
I have a solution under TFS source control and had written some sample code using an external library that was deleted a few months ago. I am certain that the code was checked in before that class file was deleted. I am able to manually browse to previous versions of...
powershell,csv
i have a csv sheet like one given below, (some cells can be empty, actual sheet i have is having upto disk 20), ID name disk1 disk2 disk3 001 abc 50 50 50 002 def 100 100 003 xyz 50 I need to input this sheet to powershell script and...
sql-server,powershell,batch-file,powershell-v2.0,powershell-v3.0
I have used select-string to validate strings found on one line, however I need PowerShell to recognise multi-line strings, as well as meeting all three conditions (see below) Output within .log file that needs to be selected: Return Value ------------ 0 I would want something to validate the following string...
powershell,iscsi
I am writing a powerscript that connects to a target through ISCSi. I need to find the new drive letters (F:, G:, …) that is created after connecting. Is there any direct way to find that? MY script would be New-IscsiTargetPortal -TargetPortalAddress $VirtualDeviceIp Connect-IscsiTarget -NodeAddress $VirtualDeviceIQN #Get the drives newly...
windows,powershell,raspberry-pi
I am trying to install Windows 10 IoT on my Raspberry Pi 2. The PowerShell documentation tells me to put in this: Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc> However, when I put it into my Windows 7 PowerShell, this comes out: At line:1 char:54 + Set-Item WSMan:\localhost\Client\TrustedHosts -Value <minwinpc> + ~ The...
powershell,readfile
I'm just wondering if it's possible to compare two text file and check if there's a difference between them? What I mean is like this, For example I have text1.txt : 123 456 789 000 and I have text2.txt : 123,test,input,bake 789,input,cake,bun Expected output : 456 does not exist in...
powershell
I'm trying to get information on all processes and services and save it into a .log. Here my Problem: Some processes have noting inside the CPU table, there I want to add something like "Nothing". How can I achieve that? That is my code so far: $ProcessTable = @{Expression={$_.ProcessName};Label="ProcessName";Width=40}, @{Expression={$_.CPU};Label="CPU";Width=20}...
arrays,regex,parsing,powershell
I'm trying to search through one column in each row of the table. I would then like to add another value to the row based on the number being search. This code produces the table: $LUNSSummary = ($NY_LUNS) -split '\s+(?=LOGICAL UNIT NUMBER)' | foreach { $Stringdata = $_.replace(':','=') New-Object PSObject...
powershell,powershell-v3.0
I'm hoping to create a parameter who's default value is the 'current directory' (.). For example, the Path parameter of Get-ChildItem: PS> Get-Help Get-ChildItem -Full -Path Specifies a path to one or more locations. Wildcards are permitted. The default location is the current directory (.). Required? false Position? 1 Default...
html,powershell
So I've coded a little script that sends me the last 24 hours event logs for my Servers in a nice HTML Email to save me having to log on to each Server, etc. It works well except some of our applications produce loads of events that I want to...
variables,powershell
I have this which gives me the WorkingSet memory usage I'm after: $mem=Get-Process spiceworks | Select-Object Name,@{Name='WorkingSet';Expression={($_.WorkingSet/1KB)}} But I'm looking to only have the actual amount as the variable so I can then work with that to monitor it. I want to set it so it alerts me if it...
c#,powershell,cmdlet
I am writing a Cmdlet for PowerShell in C#. I am subclassing a Cmdlet and NOT a PSCmdlet. Is there a way to get the current directory from PowerShell? I could do so with the PSCmdlet using GetVariableValue("pwd"). But in the Cmd class I do not have that available. Environment.CurrentDiretory...
powershell,cygwin,md5sum
I'm encountering an error when I try and run md5sum -c on a checksum file I generated. I should mention that I'm running this from PowerShell (as a script will be running this eventually) and this is the cygwin version of md5sum. I have a test file, jira_defect.txt and I've...
powershell,active-directory
How do I search AD users by UPN suffix in AD? The users are under Uofguelph/SEC213/users OU. Some users have @sec213.com suffix and some have @home.sec213.com suffix. I need to search for users who only have @sec213.com suffix. I have the following two code snippets. Code 1 gets all accounts...
session,powershell,user,server,disconnect
Is there a command to disconnect a user from a session on a server via PowerShell? To logoff i use: Logoff /server:<Server> <SessionID> ...
powershell,x509certificate
I am trying to create a script to remove all but the newest certificate from any given smart card (in the SC Reader at the time). This is something that I intend to be able to distribute to end users, so it should be self sufficient. My first issue is...
powershell
I'm trying to run curl to upload a file in my script, using batch was painful because I need to do string manipulation etc so I turned to powershell. However I can't seem to get powershell to execute Curl: $hash = "test" $fileToUpload = "hello world.txt" $user = "user" $password...
powershell,text,text-files
I'm just wondering if it's possible to read the content of text file with specific index? What I mean is like this, for example: I have text file like this, 'test1.txt' 12345678900 ## ## readthistext 54321123440 ## ## hellothistext I just want to read the content of text file after...
powershell
I found this script on here, please help me understand this better. What is the whole "gps" part of the script for? What part of this script is overwriting my original CSV and copying in the PC's taskmanager list? Processes. What does this do, why 51? ($xlOut,51) I went searching...
sql-server,loops,powershell
I'm writing a powershell script to load text files from a specific folder into SQL server database, I have manage to do so but only one file by one file. I want the program to do this automatically once the user inputs the path and the file extension. For example:...
python-2.7,powershell,subprocess
I have a line of Powershell script that runs just fine when I enter it in Powershell's command line. In my Python application which I run from Powershell, I am trying to send this line of script to Powershell. powershell -command ' & {. ./uploadImageToBigcommerce.ps1; Process-Image '765377' '.jpg' 'C:\Images' 'W:\product_images\import'}'...
arrays,powershell,file-structure
$folder = filestructure # Get a recursive list of all folders beneath the folder supplied by the operator $AllFolders = Get-ChildItem -Recurse -Path $Folder |? {$_.psIsContainer -eq $True} # Get a list of all files that exist directly at the root of the folder # supplied by the operator $FilesInRoot...
powershell
I wrote a small script to get some basic information off a few remote servers. But my output it is a bit odd. I believe my issue is with my $DRIVE function. Code: $serversList = 'svr01.xxx.com', 'svr03.xxx.com', 'svr05.xxx.com', 'svr06.xxx.com', 'svr08.xxx.com' #End of Server List Write-Output "Start of Hal0 `n"; ForEach...
powershell
I have some code that pull user accounts from an OU in AD. I am sorting it using Group-Object so I know how many users are using the same email address. Code below, the $OuUser uses Get-ADUser with Properties and Filter set to *. $Duplicates = $OUUser | Select samaccountname,...
regex,powershell
I have the following requirement. I need to list down all the tables from Golden Gate prm files. I want to use regex to pull the list from the chunk of string. The format of data looks like this: MAP AFF_INTEGRATION.SFDC_ACCOUNT , Target dbo.AFF_INTEGRATION_SFDC_ACCOUNT_EXCEPTION , --MAP AFF_INTEGRATION.SFDC_USER , Target er_service.dbo.AFF_INTEGRATION_SFDC_USER...
powershell
I'm creating a new Powershell session like so: New-PSSession -ConnectionUri https://myserver:12345 -Credential myserver\username -Authentication default This is working fine, I can do Get-PSSession and it provides me with that one session. However, when trying to pipe the result to Exit-PSSession things go haywire. So this: Get-PSSession | Exit-PSSession Or this:...
powershell,csv,datatable
I have CSV file MyFile.csv. It contains following data: RollNumber Name 1 Amol 2 Ravi Now I am fetching few records from SQL Server as follows: RollNumber Name 3 Viku 4 Vaibhav I am not able to find a way to append these new records to existing CSV file. I...
powershell
I'm trying to delete all folders in \\kiewitplaza\vdi\Appsense_profiles that end with .old. The piece I have that says Write-Host $name is just me trying to test before I delete anything. $name = Get-ChildItem "\\kiewitplaza\vdi\Appsense_profiles" if ($name.name.EndsWith(".old")) { Write-Host $name #Remove-Item "\\kiewitplaza\vdi\Appsense_profiles\$name.old" } ...
powershell,error-handling
I have a script here that reads a list of desktops and changes the administrator password of those DTs. It works but I have a minor problem. Once the error shows up in Powershell, the value is never reset. So for example the second DT failed and the third and...
powershell,input,data
I'm looking to make a super simple request for input script that uses said input to be executed in the script below. I can edit the script before I run it each time, but it would be way cooler and more practical if you could just enter the PCname and...
powershell,active-directory
I posted this question the other day Extract e-mail from grouped objects $OuUser = @{} $OuUser = Get-AdUser -Properties * -Filter * -SearchBase "domain" $Duplicates = $OuUser | Select samaccountname, mail,UserPrincipalName | Group-Object Mail | Where{$_.Count -gt 1} $Duplicates | Select Name,Count,@{l='Accounts';e={($_.Group|Select -Expand samaccountname) -join ';'}} | Export-CSV E:\Damo\Duplicates.csv -NoTypeInfo...
json,powershell,azure,server-farm
I am struggling to get the Drupal Webapp created using powershell with a GalleryTemplate Json file. It creates Serverfarm, Database servers but fails for website creation. I am not able to figure out how to move ahead as website creation need to use the created hostingplan serverfarm.It would be great...
sql,sql-server,powershell,database-connection
I have a small powershell script that is meant to get column ServerName from a remote SQL database called, Hal0Test > from table, ServerList. However, I can not figure out this Powershell Error. Newest Code: Write-Output " `n Start of Hal0 `n"; $connectionString = "Server=QAUTILITYDB01;Database=Hal0Test;Integrated Security=True;" $connection = New-Object System.Data.SqlClient.SqlConnection...
powershell,puppet
I am using powershell script to set some environment variable-- $env:FACTER_Variable_Name = $Variable_Value FACTER is for using these in the puppet scripts. My problem is - the variable name and variable value both are dynamic and getting read from a text file. I am trying to use $env:FACTER_$Variable_Name = $Variable_Value...
c#,xml,powershell
EDIT: This isn't quite the same as the posted that was linked. The main problem I was running into was appending child nodes to an empty XML node. When selecting the node directly, it would return a System.String type, which doesn't have the AppendChild method. The fix was to select...
vb.net,powershell,tfs,tfsbuild,tfs2013
I'm trying to write a powershell script to allow a user to specify a tfs build id (or alternately a changeset id) and download the build output to the current directory. I have the build configured to copy the output to the server, which means only the most recent build...
html,powershell,powershell-v2.0
I have a file output.txt having below content: SERVER_NAME MOUNT_POINT TOTAL_SPACE USED_SPACE USED_PERCENTAGE AVAILABLE_SPACE Server_1 /dev 1200G 537G 54% 464G Server_2 /dev 600G 490G 85% 94G Server_3 /dev 600G 402G 69% 181G Backup_server /storage 800G 682G 72% 278G Using following script, I formatted my output.txt file to get a notification...
powershell,stored-procedures,output-parameter
I have a stored procedure returning a string and I need the result as a powershell variable. I'm stuck on the output parameter syntax. Powershell script: $SqlConnection = New-Object System.Data.SqlClient.SqlConnection $SqlConnection.ConnectionString = "Server=myserver;Database=mydb;Integrated Security=True" $SqlConnection.Open() $SqlConnection.State $SqlCmd = New-Object System.Data.SqlClient.SqlCommand $SqlCmd.CommandText = "testsp3" $SqlCmd.Connection = $SqlConnection $op = new-object System.Data.SqlClient.SqlParameter;...
windows,powershell,batch-file,recursion,cmd
My Problem statement: Main Folder -SubFolder1 --1.jpg --2.jpg -SUbFolder2 --Subsubfolder ---1.jpg ---2.jpg I have this main folder which has subdirectories and at the last subdirectory, there are images. Now, what I wish to achieve is recursively check if image file(s) exists in a subdirectory If it does, zip all the...
windows,powershell
This is a really weird issue that only occurs on one computer that I've tested on. I have the following line of code: (get-WmiObject win32_physicalMemory -Impersonation 3 -ComputerName "localhost").Capacity which returns null for some reason. However, on the same computer, if I run the command: get-WmiObject win32_physicalMemory -Impersonation 3 -ComputerName...
powershell
I am trying to find AD users by name and surname but with converted non-english diacritics to english signs Ex. convert Ł to L etc. So I wrote: Get-ADUser -Filter * -Properties GivenName, Surname | Where-Object { [Text.Encoding]::ASCII.GetString([Text.Encoding]::GetEncoding("Cyrillic").GetBytes($_.GivenName)) -eq $name } It's working fine, but I am getting an error:...
powershell
I am trying to write a PS script that will a database and perform an action if the variable returned is not 0. I have tried in many ways, but it doesn't work. It works for other values than 0. Here is my script, using PS 3.0: Import-Module .\Invoke-SqlCmd2.psm1 $server=servername...
arrays,powershell
I'm trying to remove objects from an array that contain duplicates and only keep the ones with the highest number in TasteCode. The example below is highly simplified, but it shows the problem. Example: $Fruits Name | Color | TasteCode ----- ------ --------- Apple | Red | 2 Apple |...
powershell,parameters
I have an attribute collection defined like so: $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute] While I am able to add attributes and validateset options I am however unable to add a SwitchParameter to the collection. $SwitchParameter = New-Object System.Management.Automation.SwitchParameter $AttributeCollection.Add($SwitchParameter) When I run the above I get the following error: Cannot find...
powershell,io-redirection
I have been struggling with this problem and researching around but can't get a solution My problem: I need to run a Powershell script from inside another Powershell script and redirect the output stream to a file. So far so good. The real issue comes when I need to control...
powershell
So I'm trying to get a list of servers from AD, and then create New-PSDrive's with the $.Name and $.DNSHostname properties. $Servers = Get-ADComputer -filter blah blah gets a list of servers $Servers | ForEach-Object {New-PSDrive -PSProvider FileSystem -Credential $creds -Name $_.Name -Root \\$_.DNSHostname\D$} I think it has something to...
powershell
am using the below script to retrieve the NAME and PATH of the VM's and in the PATH am getting the full length path which i dont want it, i just need the path which is displaying after the Resources in the output here is my code: function Get-Path{ param($Object)...
powershell,access-denied,start-process
I'm trying to run start-process from a powershell script with given credential. Nevertheless the command fail with the following error: Start-Process : This command cannot be executed due to the error: Access is denied Here is the full error log: 18-Jun-2015 11:48:54 Start-Process : This command cannot be executed due...
winforms,powershell,button,click,action
I did try to make 1 button that makes 2 actions: one on the 1st press (click), the other on the 2nd press (click), and repeat. However, none of my approaches worked for me, so I made 2nd button to make 2nd action, but I would really like to have...
powershell
New to PowerShell and ran into a bit of a road block. I am trying to pull program name and version information from multiple servers. I have a list of the program names in a $list variable but the program names also contain the version numbers in them. I am...
powershell,windows-server-2012
I have a date 2015/05/28 I want to list all files using order by creation date whose creation date is greater than that using PowerShell. How could I do that? I googled for it and found Get-ChildItem "C:\Users\gerhardl\Documents\My Received Files" but no idea how to compare it with creation date...
regex,powershell,grep
I have to do a report on how many times a certain CSS class appears in the content of our pages (over 10k pages). The trouble is, the header and footer contains that class, so a grep returns every single page. So, how do I grep for content? EDIT: I...
powershell,batch-file,escaping,powershell-v2.0,comma
I have a command that I need to run in a Powershell script, the command is : ".\pacli DELETEUSER DESTUSER='"[email protected]`,com"' sessionid=333" | invoke-expression The comma (,) in here :[email protected],com is not a mistake, and that's what is giving me the hard time. I tried to escape the comma with `...