Quantcast
Channel: PowerShell
Viewing all 15370 articles
Browse latest View live

Powershell Automation (On-Boarding)

$
0
0

I have finally finished my employee turn over script and decided to keep on with the fun and start an on-boarding script. I have come to a block in trying to figure out how to go about this I will post below the two version i have of the script. What i want to achieve is creating a user, assigning them a license, adding the to certain distribution list. Where i'm stuck at is trying to figure out how to create a user and assign a license. Where i'm getting lost at is trying to figure out how i can both create a entire user with one variable and how to reference it later in the script by just the user name

Powershell
$NewUser=Import-ModuleActiveDirectoryconnect-msolserviceNew-msoluser-LicenseAssignment-sku-UsageLocationUS-Displayname-Firstname-Lastname-userPrincipalNameImport-ModuleActiveDirectory$D=get-date$searchOU=...

PowerShell Export-CSV: Missing Columns in Output

$
0
0

Data I am trying to output is from an array.

First record of array apparently has less columns than the other records, so my output also only has one column, unless I specify my columns.

My original post before adding the above preface as a quick summary:

Working with the Meraki API, I am trying to pull a list of SSIDs in use across all 250 of our networks. My script will tell me if any are disabled for any particular reason. I want this dumped to a CSV file. The problem is that it only outputs the first column, "MerakiNetwork." It does not output columns SSID00 through SSID14.

As I am writing this, I may have actually identified what is causing my problem. I just did not expect PowerShell to behave in this way. At the end of the PowerShell stuff below, I have a ForEach loop that is adding records to an array. It is only adding columns to...

Script to list AD user Member Of groups as well as what kind of group?

$
0
0

All,

I have a script that I run to get a list of all items under the Member Of tab for a specific AD user.  

My question is, is there a way for it list what type of group each group is? For example, if its a Distribution group or a Security Group?

Thanks in advance,

Dustin

Text
Get-ADPrincipalGroupMembership Tad.Carlson | select name | Export-Csv \\cleo\shared\dustin\Scripts\TadGroups.csv

Get-childitem using variable path script returns nothing

$
0
0

I've been trying to write avery simple script to search through some individual text files for a specific string.

If I hardcode my directory it returns my file, but as soon as I use a variable it doesn't return any values.

Powershell
./search.ps1"C:\\Users\\Matt\\Documents\\Scripts\\","with"

I run it from the folder I've saved the script in and know to use \\ to escape the \ when entering my pathname. The above is just my test folder and I know there is a text file includingwith in it.

Powershell
param([string]$search,[string]$directory)Get-ChildItem$directory-Filter*.txt|Select-String-Pattern$search|Select-UniquePath

How to 'Copy' a whole directory to Sharepoint using Powershell

$
0
0

How do I 'copy' a network folder and the multiple SubFolders associated with the network folder to SharePoint using PowerShell scripting?

I have the below that will copy the main folder in a directory to SharePoint. But the code will not copy the subfolders underneath that main folder correctly. What I end up with is one folder named after every subfolder. Any help is appreciated.

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
$Context.Credentials = $Cred

#Retrieve list

$List = $Context.Web.Lists.GetByTitle($DocLibName)
$Context.Load($List)
$Context.ExecuteQuery()


#Upload file

Function ImportFiles()
{

#Get name of folder
$NewDirectory = Split-Path $Directory -Leaf
#upload folder to...

Stored Variable all on one line when I write-host - need to keep multi line

$
0
0

Hello all,

First post here, hope I get this right so someone can put me out of my misery and google search hell. :-D

I'm new to Powershell, and writing a script for our team to use to help with common tasks from the hundreds of tickets we process each day. My Powershell background has been strictly one liner commands till I took a Powershell class at the Microsoft campus a few weeks ago, and now I'm 1,000 lines in and getting in over my head I think. For the most part, with some trial and error, I'm getting there. But I'm not getting far in trialing and erroring my way through this.

In Exchange Powershell and in Windows Powershell with a Remote Exchange session, this gives me a plain list of Distribution Lists a user owns/manages, one per line.

Powershell
$dlsUserOwns=Get-Recipient-Filter"ManagedBy -eq '$dlUserDN'"...

Powershell - Matching Columns

$
0
0

Column A of my spreadsheet contains either User First Name or User Last Name.

Column B of my spreadsheet contains either User Last Name or User First Name, basically the opposite of what Column A has.

Column C has for sure only user Last Name.

Is there a way in Powershell to run a match between Columns A and B, and if they do not match Column C, output the "mismatch" into Column D?

Script run

$
0
0

How to run script 

schtasks.exe /delete /tn xxx /f

I saved to the ps1 file on the desktop. I run this file but it does not execute the command.

as I manually enter the powershell code it works.
what am I doing wrong?


Invoke-Command Error ComputerName

$
0
0

Hi all,

I've got two scripts that are similar in every respect. One of them executes with no issues

Powershell
Invoke-Command-Credentialdomain\username-ComputerName(Get-Contentc:\scripts\scanner-central-admin-agent.csv)-ScriptBlock{Get-CimInstance-ClassNameWin32_Product-Filter"name like '%Scanner Central%'"|Invoke-CimMethod-MethodNameUninstall}-ErrorActionSilentlyContinue

This one gives me this error

Powershell
Invoke-Command-Credentialdomain\username-ComputerName(Get-Contentc:\scripts\lenovo.csv)-ScriptBlock{Get-CimInstance-ClassNameWin32_Product-Filter"name like '%Lenovo%'"|Invoke-CimMethod-MethodNameUninstall}-ErrorActionSilentlyContinue


The csv files have the same format.

I'm not sure where I'm going wrong. Any thoughts?

How to loop this with Powershell..

$
0
0

Hi,

The following code is repetitive, and I'm thinking on how to loop this specially given that with each Get-VDPortgroup the ActiveUplinkPort and the UnusedUplinkPort changes as can be seen below.

So for the 1st PortGroup the ActiveUplinks are dvUplink1 and dvUplink2, for the second the activeuplink is dvUplink3, and so on..

Kindly understand that I'm trying to understand the logic of looping this and NOT the script, thank you.

Text
$geVDSwitch | Get-VDPortgroup "ManagementPG" | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink1", "dvUplink2" -UnusedUplinkPort "dvUplink3", "dvUplink4", "dvUplink5", "dvUplink6", "dvUplink7", "dvUplink8", "dvUplink9" $geVDSwitch | Get-VDPortgroup "NFSPG" | Get-VDUplinkTeamingPolicy | Set-VDUplinkTeamingPolicy -ActiveUplinkPort "dvUplink3" -UnusedUplinkPort "dvUplink1",...

audit server listing through powershell

$
0
0

Got quick question for those out there that are awesome at powershell.

Asked to go onto a potential new client site. Need to audit their servers with required details, only got less than two days to go through all servers and would rather just do it through a simple command to export to CSV file. 

Need to gather:

Age

Memory - RAM - % in use

Hard Disk space - available

CPU - % in use

SCOM installed.

Patch level – up to date

Anti-Virus Installed

Any ideas out there? Any help would be appreciated....

Powershell Disk Space Report won't output to HTML

$
0
0

Hi all,

Need some help with the below powerhshell query.

The e-mail sends fine, but it outputs the HTML as plain text.

I've tried adding $body+= Converto-HTML but it doesn't change anything. I can't find anywhere where I can parse -BodyIsHTML also

Powershell
# mail message properties$fromemail="abc@abc.com"$users="abc@abc.com"$Subject="Disk Space Alert"# smtp auth details$SMTPClient="smtp.office365.com"$SMTPClient=New-ObjectNet.Mail.SmtpClient($SmtpServer,587)$SMTPClient.EnableSsl=$true$SMTPClient.Credentials=New-ObjectSystem.Net.NetworkCredential("abc@abc.com","smtp password");$SMTPClient.Send($fromemail,$users,$Subject,$body);# list properties$list="C:\Users\Desktop\diskspacereport\list.txt"$computers=get-content$list[decimal]$thresholdspace=20#assemble together all of the free disk space data...

Need help with finding and moving disabled accounts to specific OUs

$
0
0

I am trying to write a script that will find all the disabled users and then based on a string in the disabled users Distinguished Name, move them to a specific OU.

Below is what I have so far but it doesn't work and I could really use some help.

Powershell
Import-ModuleActiveDirectory$Atlanta="OU=Disabled Accounts,OU=Atlanta,DC=tcore,DC=com"$Dallas="OU=Disabled Accounts,OU=Dallas,DC=tcore,DC=com"$Hummelstown="OU=Disabled Accounts,OU=Hummelstown,DC=tcore,DC=com"$Dis=Get-ADUser-filter{Enabled-eq$false}-IdentitydistinguishedNameif($dis.dingtuishedName-match'Hummelstown'){Move-ADObject-TargetPath$Hummelstown}elseif($dis.dingtuishedName-match'tlanta'){Move-ADObject-TargetPath$Atlanta}elseif($dis.dingtuishedName-match'allas'){Move-ADObject-TargetPath$Dallas}

Delete text from Output

$
0
0

So I'm running this powershell script, but would like to remove CN= from the output. Could someone help please?

get-childitem -path Cert:\localmachine\my |Format-Wide -Property Subject

CN=Doodles1.me.dd.com

SmartDeploy question

$
0
0

So here is the goal of my current team... They want me to patch the current image we use to also copy over any default app selections so that we can effectively image a machine, and then ship it out.  I found something saying I could export this information to an XML file and then simply include it in the image.  However upon researching a bit further apparently the command I learned  dism /Online /export-defaultappassociations:\\Server\Share\Appassoc.xml is no longer effective after some windows update back in 2017... any ideas as to how I could accomplish my goal?

(I tried running that command through a standard command prompt and got error 53 which is how I got this far.)


PowerShell invoke OS command - extra quote trailing parameters

$
0
0

I'm sure I'm missing something obvious. Can anyone explain the extra quote at the end of the output?

Powershell
PSD:\Data\reset>&"cmd.exe"("/c echo "+"helloooo")helloooo"PS D:\Data\reset>

Windows Activation

$
0
0

Hello,

I've found a script to activate windows using powershell

Text
$service = get-wmiObject -query 'select * from SoftwareLicensingService' if($key = $service.OA3xOriginalProductKey){ Write-Host 'Product Key:' $service.OA3xOriginalProductKey $service.InstallProductKey($key) }else{ Write-Host 'Key not found.' } 

But it doesn't work. It gives out this error. tried different variations but nothing. Please help.

Text
Exception calling "InstallProductKey" : "" At line:3 char:1 + $service.InstallProductKey("6YXFF-NMQG3-H2886-YBH2B-HT9TP") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : WMIMethodException 

(easy) Write-host query

$
0
0

Hi, ref attached png:  My query works, I'm happy with it but am trying to understand why my variable $FileNameExt used for specifying multiple file extensions doesn't show the comma when it's written back out to the host.  If I was to replace my variable in the piped "Where ($_extension  -in $FilenameExt)" command with the  written host value "Where ($_extension -in .txt .pdf)" I fully understand why it fails.  

What I'm trying to learn & understand for future scripting is why the "write-host $FileNameExt" doesn't show the value ".txt,.pdf". 

Told you it was an easy one!

Thanks

How to get text box input from child form powershell

$
0
0

I have been working on this script for a few weeks now. I'm a newbie to powershell and windows forms. I used PS2EXE to make an exe so it was easier for the intended users to open. I have started adding a settings menu to it just in case I have to change the location of the files it copies. The child form currently does nothing just opens and shows the hard coded path. How do I pass what is typed into textbox2.text on the child form to the variable sourceDirectory? If I tried making sourceDirectory = textbox2.text I got an error that the path was null.

Powershell
Add-Type-AssemblyNameSystem.Windows.Forms[System.Windows.Forms.Application]::EnableVisualStyles()$Form=New-Objectsystem.Windows.Forms.Form$Form.ClientSize='400,400'$Form.text="Projects Folder Creation Tool"$Form.TopMost=$false$TextBox1=New-Objectsystem....

Get list of folders in a directory and set each as an individual variable?

$
0
0

Hello folks,

Powershell
$RecentBackups=Get-ChildItem-Path$SourcePath|Sort-ObjectLastWriteTime-Descending|Select-Object-First5$TopFive=$RecentBackups.Name

I am needing to get a list of the most recent folders in a Directory, I am just curious if I can set each folder name as it's own variable. The folders are backed up workstations and the folder name itself is the backed up Computer Name.

I don't much care what the variable name is called, but they can just be set as Workstation 1-5, I'll be doing a little reading on this, so if I find a solution I'll post an update.

Example:

$Workstation1

$Workstation2

$Workstation3

$Workstation4

$Workstation5

Viewing all 15370 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>