Quantcast
Channel: Windows PowerShell forum
Viewing all 21975 articles
Browse latest View live

Get-Childitem certifications and properties

$
0
0

Hi,

I'm struggeling with the certifications and the object properties.

I store the certs like this:

$certs=get-childitem cert:\localmachine\my -recurse | fl -Property *

Now i want to handle the certs 1by1 but i cannot get the properties.

Now the certs are in $cert but i cannot list the properties. If i use Select -property Notafter or any other its empty.

How does it work? Aren't these normal properties? Do i have search the string to have the data i need?

Thanks!



Is it possible to do below steps in scripting ?

$
0
0

How to add Secure Email in Office 365

1.Open Outlook
2.Click on Create New in the Quick Steps box



3.Change the name to “Secure – New” (Note the name can be anything but it needs to be short to see it all)  Also click the drop down and select New Message and click Show Options

4. Add “[marked for secure delivery]” into the subject and click Finish

  

Powershell Simple addition of array element integers

$
0
0

Hi

I'm able to do this simple task in VBS but can't figure out the syntax in PS.  Basically I need to gather the total disk space used for a number of files in different folders. Thant I can happily do and have a simple array with integer amounts: eg

 PS C:\> $size

 107327185408
 375809638912

the question is how do I add these element together? Seems simple but I can't find the correct formatting to sum these items.

thanks

Powershell Scripts - Restrict and Limit Access

$
0
0

Hi,

I made some "sensitive" scripts I need to make accessible  to others, in order to other team can execute them.

preferrably just give them access to execute the scripts on some remote location/proxy and not give them the scripts code.

What are the alternatives to do this and recommended approaches?

I'm not quite in the details of JEA/JIT/Remote PS and would like your advice on this. 

Thanks,

JD

Variables in an XML file

$
0
0

I have a script to get drive space and an XML file.

I am having trouble running the "foreach ($disk in $diskLettersControllers){}" in powershell.  The script sees the C and D
as one drive rather than 2 drives, and getting the space fails. How do I split the C and D?

<?xml version="1.0" encoding="utf-8"?>
<Settings>
   <environment>Site</environment>
  <DeliveryControllers>Servername</DeliveryControllers>
  <diskLettersControllers>"C:, D:"<diskLettersControllers>
</Settings>

Create mountpoint script overwriting partitions

$
0
0

Hi All.

I have been able to put together the script below, it creates mount points from a single disk at the moment, instead of hardcoding things, I decided to put it within a loop, the issue i am finding is that some of the partitions are overwritten as i do not know the last partition number programatically, this is needed so as to increment the partition number by one for the next mount point.

$all_drives = (Get-Volume).DriveLetter
if ($all_drives -notcontains 'D')
{
	$root_drive = "D"
	New-Partition  -DiskNumber 1 -DriveLetter $root_drive -Size 40GB
	Format-Volume -DriveLetter $root_drive  -FileSystem NTFS -NewFileSystemLabel “SQL D” -Confirm:$false -Force

}




$root_drive = "E"
New-Partition  -DiskNumber 1 -DriveLetter $root_drive -Size 1GB
$root_drive = "E"
Format-Volume -DriveLetter $root_drive  -FileSystem NTFS -NewFileSystemLabel “Root E” -Confirm:$false -Force


$data_disk = 15GB
$log_disk = 10GB
$tempdb_disk = 10GB
$sys_disk = 10GB
$dump_disk = 10GB

$all_drives = (Get-Volume).DriveLetter
if ($all_drives -contains 'E')
{


	$mounts = @("DATA","LOG","SYS","TEMPDB","BACKUP")

	foreach ($mountpoints in $mounts)
	{


			$noofdrives = 1
			$root_drive = "E:"
            $disk_no = 1

			$partition = 1
			For ($i=1; $i -le $noofdrives ; $i++) 
			{
				switch ($mountpoints)
				{"DATA" {$disk_allocation = $data_disk; break}"LOG" {$disk_allocation = $log_disk; break}"SYS" {$disk_allocation = $sys_disk; break}"TEMPDB" {$disk_allocation = $tempdb_disk; break}"BACKUP" {$disk_allocation = $dump_disk; break}
					default {10; break}
				}

			  $partition = $mounts.IndexOf($mountpoints) + 3

			   write-host "Disk no is $i and partition number is $partition and capacity is mount point $mountpoints and disk = $disk_allocation.ToString()"

					   $datadirtype = $root_drive + "\$mountpoints"+ $i.ToString('00')
					   New-Item $datadirtype –ItemType Directory
					   New-Partition –DiskNumber $disk_no -Size $disk_allocation
					   Add-PartitionAccessPath -DiskNumber $i -PartitionNumber 2 –AccessPath $datadirtype
					   Get-Partition –Disknumber $disk_no –PartitionNumber $partition | Format-Volume –FileSystem NTFS –NewFileSystemLabel $datadirtype -AllocationUnitSize 65536 –Confirm:$false
			


			}

	}

}

What appears to be happening is that E: is then overwritten as E:\DATA01 with 1GB, it should be E: with 1GB and E:\DATA01 with 15GB.

Verify my account

$
0
0

Hello, I would like to publish a question but I can't publish name, I have the message : 

  • Body text cannot contain images or links until we are able to verify your account.

Can you please verify my account ?

Thanks in advance.

BR.

Getting around the double hop authentication issue using credssp

$
0
0

Hi,

I have a simple Ps script, which runs on ServerA, connects to server B and then tries to copy a file from a share which is on another server onto server B.

Its hitting Permission issues and i know its to do with the double hop issue, loads of info on this forum however the post i found, the links are now dead, i just need an explanation or a link where i can read exactly what needs to be done to make this work.

When I login to Server B and do a "Run As" using thesame account that my script runs as in ServerA, the copy works well so i am convinced its to do with delegation/double hop issue.

Thanks.


How to manipulate and clean up output to display only a GUID?

$
0
0

I am trying to retrieve GUIDs from SCCM and toss those in an SQL query, but I first need to get the GUIDs to perform the latter. 

Here is a one-liner I put together that retrieves the GUIDs:

$SMSGUIDs = Get-CimInstance -NameSpace "root\SMS\site_$($SiteCode)" -ClassName SMS_StatMsgWithInsStrings -ComputerName $SiteServer | 
Where-Object -FilterScript {$_.MessageID -eq '5446' -or $_.MessageID -eq '5447'} | Select-Object -Property InsString2 -Unique | 
Out-String -OutVariable SMSGUIDs

However, the issue with this is that there are additional characters in the output that I do not want that look like this:

GUID:4c589841-12a5-4cf8-90b9-b4fe4bed0b2c                
Client(SMSID = GUID:7d795378-4bb2-42cd-96fb-e3b7da7eaaba)
GUID:AB772008-BE74-4DBD-B9EB-8686830E91FE                
Client(SMSID = GUID:7e36f7a0-9977-4b35-9cc1-e23bc29a649d)
GUID:ac9d940d-e30a-40b6-9036-f7a8869f1387                
Client(SMSID = GUID:59dfc5a9-0e62-4531-bccf-2538021a5652)
Client(SMSID = GUID:d0ff6cb6-f347-4d07-8694-845d02407eda)
Client(SMSID = GUID:8b53edd3-682b-4eee-b721-28683c7398e5)
Client(SMSID = GUID:5bccf053-7e71-4652-8f52-1e9198b1099b)
GUID:cf7506bf-da70-4ddd-9454-414c19012107                
GUID:4b1405fc-2e7c-487b-9721-c8140c9d4af7                
GUID:3588B989-EB19-4330-BE16-C9DCFCD68728                
Client(SMSID = GUID:c8cb1f89-fac3-47bb-bb73-0e5994fb2d19)
GUID:1ADD0309-E246-4211-B551-21E1A4B906F1                
Client(SMSID = GUID:a09f5a1d-c4f2-4950-8094-e05de1f8704f)

I just need to filter out everything other than the GUIDs. 

I tried this, but it did not work for me:

$SMSGUIDs -match("^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$")

Thank you


power shell script for getting list of members from Intune group

$
0
0

Hi All,

please provide PowerShell script for getting list of members added in Intune group. Thank you.

change time format

$
0
0

Hi,

I am executing the below command to get the all computers local built-in administrator password  and password expiry time

get-adcomputer -Filter * -Properties * | select @{Label="Name";Expression={$_.name}}, @{Label="OS";Expression={$_.operatingsystem}}, @{Label="Distinguished name";Expression={$_.'distinguishedname'}}, @{Label="Password ExpirationTime";Expression={$_.'ms-Mcs-AdmPwdExpirationTime'}}, @{Label="Password";Expression={$_.'ms-Mcs-AdmPwd'}} | Export-Csv C:\laps.csv -NoTypeInformation -Append

password expiry time is displaying like 132092891835963000

Output file generates in CSV format. Please help how to change the format to date like 7/24/2019  12:00:00 AM


Regards, Boopathi

Delegate Rights to Add Computer Objects to a OU for one User with Powershell

$
0
0

Hi,

I would like to delegate this complex rights via Powershell.

The OU Name is OU=RDSH,OU=Clients,DC=XXX,DC=dom

The Username: svc_vm_join_ad

Access Right:

Reset password applied to Descendant computer objects

Read/write all properties applied to Descendant computer objects

I hope this description is ok.

I have write this part but I don't know that I must write for the user permission:

Import-Module ActiveDirectory
$rootdse = Get-ADRootDSE
$domain = Get-ADDomain

$guidmap = @{ }
Get-ADOject -SearchBase ($rootdse.SchemaNamingContext) -LDAPFilter '0(schemaidguid=*)' -Properties lDAPDisplayName, schemaIDGUID |
	ForEach-Object{
		$guidmap[$_.lDAPDisplayName] = [System.GUID]$_.schemaIDGUID
	}

$ou = Get-ADOrganizationalUnit -Identity 'OU=RDSH,OU=Clients,DC=XXX,DC=dom' -Server XXX-dc01.XXX.dom
$oupath="AD:\$($ou.DistinguishedName)"
$sid=(Get-ADGroup "RDSH").SID
$p = New-Object System.Security.Principal.SecurityIdentifier($sid)
$acl = Get-ACL $oupath
$ace=New-Object System.DirectoryServices.ActiveDirectoryAccessRule($p, 'WriteProperty,WriteDacl', 'Deny', 'Descendents', $guidmap['user'])
$acl.AddAccessRule($ace)
$acl|Set-ACL $oupath

How to download .CSV using Power Shell

$
0
0

Hello,I am lookning to automate the power shell script in task manager that would download the .CSV file from the web page. The web page has a trend and if you click the button (3 lines) above trend there is option to download .CSV file. The web page is here: Any help would be apreciated.Thanks,covics

How to add value in JSON Array using PowerShell

$
0
0

How do I add value to the following JSON under Resource

{
"Sid": "AmazonS3Access",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": [
"arn:aws:s3:::123",
"arn:aws:s3:::123/*",
"arn:aws:s3:::456*",
"arn:aws:s3:::456/*"
]
}

My target is to add following two value

"arn:aws:s3:::789*"
"arn:aws:s3:::789/*"

I have tried Add after importing JSON using ConvertFrom-Json, but didn't work.

$ImpJSON.Resource.Add(""arn:aws:s3:::789*"")

Note: JSON format is fixed, as you can see it is AWS IAM policy, but all the values are variable, so, it should be dynamic.

Any idea?


Regards, Saugata D

Removing drive letter using Powershell

$
0
0

Hi guys,

Newbie here with Powershell, just to let you know!

I am trying to remove a drive letter using powershell using the below code (File name: RemoveDL.ps1):

$drive = gwmi win32_volume -Filter "DriveLetter = 'Q:'"
$drive.DriveLetter = ":"
$drive.put() 

I have also created a batch file to run this with the code as follows (File name: RunRemoveDL.bat):

powershell "C:\Users\dan\desktop\RemoveDL.ps1"


I have then created a shortcut of the file RunRemoveDL.bat and then went to Properties > Shortcut > Advanced and ticked 'Run as administrator'.

However the issue I am having is that, when I running  it is still giving an access denied message. Whole error message shown below:

Exception calling "Put" with "0" argument(s): "Access is denied."
At C:\Users\Dan\Desktop\RemoveDL.ps1:3 char:1+ $drive.put()+ ~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException+ FullyQualifiedErrorId : DotNetMethodException

So my two questions about this are:

1) How can I run the powershell script as administrator without right clicking and selecting 'Run as administrator'?

2) Is this the best way to remove a drive letter or is there a better script/(s) I can use?

Thanks,

Dan Goodwin


Forum Posting Guidelens

$
0
0

send a file via email using a condition (Powershell Script)

$
0
0

as you show in the example below (CSVfile) i would like to send the PDF file using the path to the appropriate email, to 149 users automatically.
I like to know how I can do it using a powershell script

Email	                                  link
amir.belgaied@***.com	   c:\\desktop\amirbelgaied.pdf
anis.hani@***.com	           c:\\desktop\anishani.pdf

*
*
*
*
*

Best Reagards

Amir


powershell not trusting signed certificate

$
0
0

Hi everyone,

we have the following situation (and google + technet didn't get me to an answer yet - if i failed at searching, i'm willing to take your blame :D):

Issue:

  • we are using an internal certificate authority to provide "Code Signing" certs for our Powershell scripts
  • we set the registry of all machines to run Powershell scripts "Remote Signed" (no GPO, to be able to temporarily overwrite it)
  • we put signed scripts into a central DFS
  • we run the scripts and get the following error on a hand full of servers (not all, not any specific one):

File \\DFS\<MyScript>.ps1 is published by CN="MyUser", OU=SomeOU, DC=my, DC=personal, DC=domain and is not trusted on your system. Only run scripts from trusted publishers.
[V] Never run  [D] Do not run  [R] Run once  [A] Always run  [?] Help (default is "D")

Meta-Informations:

  • we have servers with: Windows Server 2008 R2 and Windows Server 2012 R2 affected
  • Powershell 5.1(14393.2969)
  • issue can not be pin pointed to a specific OS or PS version
  • we have two certificate authorities (just recently did a redesign and build a newer CA)
  • both have our Code Signing template
  • both can issue those and you can sign scripts perfectly fine
  • all affected systems neither accept code signing from the old nor the new CA
  • we checked the installed Windows Server OS, Patches and Powershell versions - nothing indicates a specific problem
  • we upgraded everything to the newest possible versions
  • we double checked the certificates, the local certificate trust (old and new CA are trusted), we added the signing person to the local trust, we checked the connection to the CA to verify the system can check the validity of the used cert, we use a timestamp server for script signing, we even checked the complete network connection (local and network firewalls) for any indication

We are currently at a dead end and need some help to find a solution for this issue.

Do you have any tip or trick on how to further analyze this issue?

Thank you in advance!

Best regards

Matthias / TheAlcesh

New user script issues

$
0
0

Import-Module activeDirectory 
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
$Firstname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter First Name", "Create New User")
[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
$Lastname = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Lastname", "Create New User") | Out-Null
$title = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Job title ", "Create New User")| Out-Null
$email = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Job Email", "Create New User") | Out-Null
$department = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Job Department", "Create New User")| Out-Null
$street = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Street", "Create New User") | Out-Null
$city = [Microsoft.VisualBasic.Interaction]::InputBox("Enter City", "Create New User")| Out-Null
$postalcode = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Post Code", "Create New User")
$homephone = [Microsoft.VisualBasic.Interaction]::InputBox("Enter Phone Number", "Create New User")
$PWD=[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null 
$PWD= [Microsoft.VisualBasic.Interaction]::InputBox("Enter Password ", "Create New User")
$dnsroot = '@' + (Get-ADDomain).dnsroot
$Dname="$firstName " + "$LastName"
$UPN = Get-adforest | select UPNSuffixes -ExpandProperty UPNSuffixes | Out-GridView -PassThru | Select-Object -ExpandProperty UPNSuffixes
$company = "Test Company"
$ou = Get-ADOrganizationalUnit -Filter * | Select-Object -Property DistinguishedName | Out-GridView -PassThru | Select-Object -ExpandProperty DistinguishedName
New-ADUser -Name "$firstName $lastName" -Displayname $Dname -AccountPassword (ConvertTo-SecureString “$pwd” -AsPlainText -force) -GivenName $FirstName  -title $title -EmailAddress $email -Department $department -Company $Company -StreetAddress $street -city $city -PostalCode $postalcode -HomePhone $homephone -SamAccountName "$firstName.$lastName" -Surname $LastName  -UserPrincipalName "$firstName.$lastName@$UPN" -Path $OU -Enabled $TRUE
for ($i = 1; $i -le 100; $i++ )
{
    Write-Progress -Activity "User creation in Progress" -Status "$i% Complete:" -PercentComplete $i;
}
Write-Output "User $Firstname $lastName has been created"

User being added into a Skype for Business conferencing policy who should not be added

$
0
0

Hi,

I am testing the below, but for some reason it is adding 1 user into the new policy who is not in the below test group.

$groupmember = Get-ADGroupMember test-p2pfiletransfer | Get-ADUser
foreach ($member in $groupmember)
{
$aduser = Get-Csuser -Identity $member.UserPrincipalName | Where-Object {$_.HostingProvider -eq "SRV:"}
Get-CsUser -Identity $aduser.identity | Grant-CsConferencingPolicy -PolicyName EnableP2PFileTransfer
}

If I run the below command it doesn't output the user who should't be being added into the policy. It does ouput a user who should be added into the policy which is fine.

Get-Csuser -Identity $member.UserPrincipalName | Where-Object {$_.HostingProvider -eq "SRV:"}

The user who shouldn't be added into the list is the very first user who is displayed in the SfB Control panel when sorted from A to Z. Not too sure if that is making a difference or not.



Viewing all 21975 articles
Browse latest View live